配置 Python 2.7 以使用模块
我在Windows 32位系统上安装了Python 2.7、OpenCV2.2、Numpy 1.51、SCIPY 0.9.0和PIL 1.1.7。当从安装目录(即 C:\Program Files\Python27)调用 Python 时,一切正常(即我可以导入模块)。但是,如果我从任何其他目录启动Python,则无法加载模块(例如ImportError:没有名为PIL的模块)。我的系统变量如下:
PATH= ...;;C:\Program Files\Python27;C:\Program Files\OpenCV2.2\bin PYTHONPATH=C:\Program Files\Python27\Lib\site-packages;C:\Program Files\OpenCV2.2\Python2.7\Lib\site-packages
我缺少什么?
I installed Python 2.7, OpenCV2.2, Numpy 1.51, SCIPY 0.9.0 and PIL 1.1.7 on a Windows 32-bit system. Everything works fine (i.e. I can import modules) when Python is called from the directory it is installed in (i.e. C:\Program Files\Python27). However, I cannot load modules (e.g. ImportError: No module named PIL) if I Python is started from any other directory. My System variables are as follows:
PATH= ...;;C:\Program Files\Python27;C:\Program Files\OpenCV2.2\bin
PYTHONPATH=C:\Program Files\Python27\Lib\site-packages;C:\Program Files\OpenCV2.2\Python2.7\Lib\site-packages
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该设置
PYTHONPATH
环境变量。http://docs.python.org/using/cmdline.html#envvar-PYTHONPATH
由于某种原因,在我的 Linux 系统上,未设置此变量。但是如果我进入 Python shell 并运行:
它会显示我所有模块的位置。
You should set the
PYTHONPATH
environment variable.http://docs.python.org/using/cmdline.html#envvar-PYTHONPATH
For some reason on my Linux system, this variable isn't set. But if I go into the Python shell and run:
it shows the location of all my modules.