怎么在Path中matlab中如何添加路径Python路径

求帮助,已经将路径加入到了sys.path中,为什么还不能导入模块【python吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:177,668贴子:
求帮助,已经将路径加入到了sys.path中,为什么还不能导入模块收藏
我已经将模块路径添加到了sys.path中,为什么还是不能导入模块啊?我想在comm_seg_pos.py中导入模块jieba_tool.附图,求帮助!谢谢comm_seg_pos.py部分代码试过了sys.path.append('..')也没用,急,谁有好的解决方法?
51CTO学院12年行业品牌,1600万用户选择,中国专业IT技能学习平台.python资深名师授课,0基础从入门到精通,python报名与培训中心.
请看图,本软件已实现相对路径导入包,来这里xfqq.wodemo.com包教会,
登录百度帐号Python sys.path详细介绍
转载 & & 作者:
这篇文章详细介绍了Python sys.path,有需要的朋友可以参考一下
如何将路径“永久"添加到sys.path?
sys.path是python的搜索模块的路径集,是一个list
代码如下:['', 'C:\\WINDOWS\\system32\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\ \lib', 'C:\\Python26\\lib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26 ', 'C:\\Python26\\lib\\site-packages', 'C:\\Python26\\lib\\site-packages\\win32' , 'C:\\Python26\\lib\\site-packages\\win32\\lib', 'C:\\Python26\\lib\\site-packa ges\\Pythonwin']
可以在python 环境下使用sys.path.append(path)添加相关的路径,但在退出python环境后自己添加的路径就会自动消失!
在python脚本中修改
代码如下:import syssys.path.append('c:\\mypythonlib')
为解决这个问题,可以有以下方法:
1. 将自己做的py文件放到 site_packages 目录下:
下面命令显示了 site-packages 目录:
代码如下:python -c "from distutils.sysconfig import get_python_ print get_python_lib() "
但是这样做会导致一个问题,即各类模块都放到此文件夹的话,会导致乱的问题,这一点是显而易见的。
注意,也不创建子文件夹,再将自己的模块放到子文件夹解决问题,这会导致使用import 语句时错误。
2. 使用pth文件,在 site-packages 文件中创建 .pth文件,将模块的路径写进去,一行一个路径,以下是一个示例,pth文件也可以使用注释:
# .pth file for the my project(这行是注释)E:\DjangoWordE:\DjangoWord\mysiteE:\DjangoWord\mysite\polls
这个不失为一个好的方法,但存在管理上的问题,而且不能在不同的python版本中共享。
3. 使用PYTHONPATH环境变量,在这个环境变量中输入相关的路径,不同的路径之间用逗号(英文的!)分开,如果PYTHONPATH 变量还不存在,可以创建它!
路径会自动加入到sys.path中,而且可以在不同的python版本中共享,应该是一样较为方便的方法。
关于与python相关的环境变量有那些,请参考:
http://docs.python.org/using/cmdline.html
在页面上找到PYTHONPATH
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具博主最新文章
博主热门文章
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)Python - add PYTHONPATH during command line module run - Stack Overflow
Join Stack Overflow to learn, share knowledge, and build your career.
or sign in with
I want to run:
python somescript.py somecommand
But, when I run this I need PYTHONPATH to include a certain directory. I can't just add it to my environment variables because the directory I want to add changes based on what project I'm running. Is there a way to alter PYTHONPATH while running a script? Note: I don't even have a PYTHONPATH variable, so I don't need to worry about appending to it vs overriding it during running of this script.
21.3k35129217
PYTHONPATH=/foo/bar/baz python somescript.py somecommand
For Windows, setup a wrapper pythonpath.bat;
set PYTHONPATH=%1
python %2 %3
and call pythonpath.bat
pythonpath.bat /foo/bar/baz somescript.py somecommand
31.5k76485
import sys
sys.path.append('your certain directory')
Basically sys.path is a list with all the search paths for python modules. It is initialized by the interpreter. The content of PYTHONPATH is automatically added to the end of that list.
12.8k1976101
If you are running the command from a POSIX-compliant shell, like bash, you can set the environment variable like this:
PYTHONPATH="/path/to" python somescript.py somecommand
If it's all on one line, the PYTHONPATH environment value applies only to that one command.
$ echo $PYTHONPATH
$ python -c 'print("/tmp/pydir" in sys.path)'
$ PYTHONPATH=/tmp/pydir python -c 'print("/tmp/pydir" in sys.path)'
$ echo $PYTHONPATH
63.2k12110138
You may try this to execute a function inside your script
python -c " sys.path.append('/your/script/path'); yourscript.yourfunction()"
This is for windows:
For example, I have a folder named "mygrapher" on my desktop. Inside, there's folders called "calculation" and "graphing" that contain Python files that my main file "grapherMain.py" needs. Also, "grapherMain.py" is stored in "graphing". To run everything without moving files, I can make a batch script. Let's call this batch file "rungraph.bat".
set PYTHONPATH=%cd%\%cd%\calculation
python %cd%\grapher\grapherMain.py
This script is located in "mygrapher". To run things, I would get into my command prompt, then do:
&cd Desktop\mygrapher (this navigates into the "mygrapher" folder)
&rungraph.bat (this executes the batch file)
2,07642134
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabled}

我要回帖

更多关于 数据库中添加图片路径 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信