[英]Ubuntu add directory to Python path
I want to run third part tool written in python on my ubuntu machine ( corgy tool ).我想在我的 ubuntu 机器上运行用 python 编写的第三方工具( corgy tool )。
However I don't know how to add additional modules to Python path.但是我不知道如何向 Python 路径添加其他模块。
cat doc/download.rst
There is currently no setup.py, so you need to manually add
the download directory to your PYTHON_PATH environment variable.
How can I add directory to PYTHON_PATH?如何将目录添加到 PYTHON_PATH?
I have tried:我努力了:
export PYTHON_PATH=/home/user/directory:$PYTHON_PATH && source .bashrc
export PATH=/home/user/directory:$PATH && source .bashrc
python
import sys
sys.path.append("/home/user/directory/")
But when I try to run this tool I get:但是当我尝试运行这个工具时,我得到:
Traceback (most recent call last):
File "examples/dotbracket_to_bulge_graph.py", line 4, in <module>
import corgy.graph.bulge_graph as cgb
ImportError: No module named corgy.graph.bulge_graph
Create a .bash_profile
in your home directory.在您的主目录中创建一个
.bash_profile
。 Then, add the line然后,添加行
PYTHONPATH=$PYTHONPATH:new_dir
EXPORT $PYTHONPATH
Or even better:或者甚至更好:
if [ -d "new_dir" ] ; then
PYTHONPATH="$PYTHONPATH:new_dir"
fi
EXPORT $PYTHONPATH
The .bash_profile
properties are loaded every time you log in.每次登录时都会加载
.bash_profile
属性。
The source
command is useful if you don't want to log in again.如果您不想再次登录,则
source
命令很有用。
@fedorqui 's answer above was almost good for me, but there is at least one mistake (I am not sure about the export
statement in all caps, I am a complete newbie). @fedorqui上面的回答对我来说几乎是好的,但至少有一个错误(我不确定所有大写的
export
语句,我是一个完整的新手)。 There should not be a $
sign preceding PYTHONPATH in the export statement.在导出语句中 PYTHONPATH 之前不应有
$
符号。 So the options would be:所以选项是:
Create a .bash_profile in your home directory.
在您的主目录中创建一个 .bash_profile。 Then, add the line
然后,添加行
PYTHONPATH=$PYTHONPATH:new_dir export PYTHONPATH
Or even better:
或者甚至更好:
if [ -d "new_dir" ] ; then PYTHONPATH="$PYTHONPATH:new_dir" fi export PYTHONPATH
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.