python在$ PATH中时说“没有名为nest的模块" [英] python says “no module named nest” when it is in the $PATH

查看:112
本文介绍了python在$ PATH中时说“没有名为nest的模块"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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:

  1. 使用distutils-运行python setup.py install会将软件包安装到当前发行版的site-packages
  2. --user传递给setup.py install在Unix上将模块安装到~/.local/lib/python2.7/site-packages,并且在正常情况下该目录始终包含在sys.path中;
  3. --home=$HOME传递给setup.py install会将模块安装在$HOME目录下.此目录应明确包含在sys.path中;
  4. 修改python搜索路径:
  1. using distutils - running python setup.py install installs the package to site-packages of your current distribution;
  2. passing --user to setup.py install installs module to ~/.local/lib/python2.7/site-packages on Unix, and this directory in under normal conditions always included in sys.path;
  3. passing --home=$HOME to setup.py install installs module under $HOME directory. This directory should be included to sys.path explicitly;
  4. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆