python在$ PATH中时说“没有名为nest的模块" [英] python says “no module named nest” when it is in the $PATH
问题描述
import nest
在$PATH
中时给出没有名为nest的模块"错误,这意味着我的系统$PATH
中有一个/opt/nest/lib/python2.7/site-packages:
.在此位置有一个名为nest
的目录,并且nest
目录内的结构如下:
import nest
gives the 'no module named nest' error when it is in the $PATH
, which means that there is a /opt/nest/lib/python2.7/site-packages:
in my system $PATH
. At this location there is a directory named nest
and the structure inside the nest
directory is looks like:
,显然是__init__.py
.那么,为什么python无法找到nest
?
, where there is an __init__.py
obviously. So why can't python find nest
?
更多信息:
我确定我在python2.7上安装了nest,并使用相同的python2.7运行它.
I am sure that I installed nest with python2.7, and run it with the same python2.7.
推荐答案
根据 docs ,有几种安装python软件包的方法:
According to the docs, there are several ways to install python packages:
- 使用
distutils
-运行python setup.py install
会将软件包安装到当前发行版的site-packages
; - 将
--user
传递给setup.py install
在Unix上将模块安装到~/.local/lib/python2.7/site-packages
,并且在正常情况下该目录始终包含在sys.path
中; - 将
--home=$HOME
传递给setup.py install
会将模块安装在$HOME
目录下.此目录应明确包含在sys.path
中; - 修改python搜索路径:
- using
distutils
- runningpython setup.py install
installs the package tosite-packages
of your current distribution; - passing
--user
tosetup.py install
installs module to~/.local/lib/python2.7/site-packages
on Unix, and this directory in under normal conditions always included insys.path
; - passing
--home=$HOME
tosetup.py install
installs module under$HOME
directory. This directory should be included tosys.path
explicitly; - modifying python search path:
您可以选择
import sys
sys.path.append('/opt/nest/lib/python2.7/site-packages')
在脚本的开头;或者您可以添加
in the beginning of your script; or your can add
PYTHONPATH=/opt/nest/lib/python2.7/site-packages
export PYTHONPATH
在~/.bash_profile
文件的末尾.
更新:
只是尝试安装nest
,发现它有两种版本-32位(在/opt/nest/lib
下)和64位(在/opt/nest/lib64
下).您可能尝试将32位python软件包与64位python发行版一起使用.尝试将./zshrc
中的字符串更改为
PYTHONPATH=/opt/nest/lib64/python2.7/site-packages
,然后查看是否有效.至少对我有用.
Just tried to install nest
and found that it comes in two flavours - 32bit (under /opt/nest/lib
) and 64bit (under /opt/nest/lib64
). You might have tried to use 32-bit python package with 64-bit python distribution. Try to change the string in ./zshrc
to
PYTHONPATH=/opt/nest/lib64/python2.7/site-packages
and see if it works. It works for me at least.
这篇关于python在$ PATH中时说“没有名为nest的模块"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!