[英]python: pytz package installation issue: ImportError: No module named pytz
I installed the pytz package on my windows7 machine via: 我通过以下方式在Windows7机器上安装了pytz软件包:
C:\Users\name\Downloads\pytz>easy_install --upgrade pytz
Searching for pytz
Reading http://pypi.python.org/simple/pytz/
Reading http://pytz.sourceforge.net
Reading http://sourceforge.net/project/showfiles.php?group_id=79122
Reading http://www.stuartbishop.net/Software/pytz
Reading http://sourceforge.net/projects/pytz/
Best match: pytz 2013b
Downloading http://pypi.python.org/packages/2.7/p/pytz/pytz-2013b-py2.7.egg#md5=7cfcc57ddb87125a042b70c03580d6cf
Processing pytz-2013b-py2.7.egg
Moving pytz-2013b-py2.7.egg to c:\python27\lib\site-packages
Adding pytz 2013b to easy-install.pth file
Installed c:\python27\lib\site-packages\pytz-2013b-py2.7.egg
Processing dependencies for pytz
Finished processing dependencies for pytz
C:\Python27\Lib\site-packages>dir
Volume in drive C has no label.
Volume Serial Number is 485C-3867
I checked that the .egg file is in the python27\\lib\\site-packages directory: 我检查了.egg文件是否在python27 \\ lib \\ site-packages目录中:
Directory of C:\Python27\Lib\site-packages
04/05/2013 06:06 PM <DIR> .
04/05/2013 06:06 PM <DIR> ..
04/05/2013 06:06 PM 237 easy-install.pth
09/20/2006 10:05 AM 126 easy_install.py
04/05/2013 05:33 PM 312 easy_install.pyc
04/05/2013 05:33 PM 312 easy_install.pyo
10/19/2009 06:35 AM 85,435 pkg_resources.py
04/05/2013 05:33 PM 90,779 pkg_resources.pyc
04/05/2013 05:33 PM 90,779 pkg_resources.pyo
04/05/2013 06:06 PM 521,259 pytz-2013b-py2.7.egg
03/08/2011 10:39 AM 121 README.txt
04/05/2013 05:33 PM <DIR> setuptools
04/05/2013 05:33 PM <DIR> setuptools-0.6c11-py2.7.egg-info
09/20/2006 10:05 AM 2,362 site.py
04/05/2013 05:33 PM 1,719 site.pyc
04/05/2013 05:33 PM 1,719 site.pyo
04/05/2013 05:36 PM 1,784,796 sqlalchemy-0.8.0-py2.7.egg
04/05/2013 05:27 PM <DIR> xlrd
04/05/2013 05:27 PM 975 xlrd-0.7.3-py2.7.egg-info
But when I go to the python interpreter I get: 但是当我转到python解释器时,我得到:
>>>import pytz
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named pytz
When I open up a .py file in PyDev it claims that the import pytz
statement is unresolved. 当我在PyDev中打开.py文件时,它声称未解析
import pytz
语句。 It can't find the package. 它找不到包。
I would kindly appreciate some help. 我将不胜感激。 Thank you.
谢谢。
* EDIT * * 编辑*
The contents of easy_install.pth
: easy_install.pth
的内容:
import sys; sys.__plen = len(sys.path)
./sqlalchemy-0.8.0-py2.7.egg
./pytz-2013b-py2.7.egg
import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)
I removed the ./pytz-2013b-py2.7.egg
from the easy_install.pth
file and tried easy_install pytz
. 我从
easy_install.pth
文件中删除了./pytz-2013b-py2.7.egg
,并尝试了easy_install pytz
。 This time it installed and I can import pytz
without the error reported earlier (why would this fix the issue?). 这次安装了它,我可以
import pytz
而没有先前报告的错误(为什么这可以解决问题?)。
HOWEVER, my ecplise/pydev still does not seem to acknowledge the import pytz
statement. 但是,我的ecplise / pydev似乎仍然不承认
import pytz
语句。 It can't resolve it. 它无法解决。 It also can't resolve
import sqlalchemy
but the dos python interpreter can import both. 它也无法解析
import sqlalchemy
但是dos python解释器可以同时导入两者。 The python interpreter in eclipse/pydev is set to C:\\Python27\\python.exe
if you go to Windows > Preferences > Interpreter - Python
. 如果转到
Windows > Preferences > Interpreter - Python
-Python,则eclipse / pydev中的python解释器设置为C:\\Python27\\python.exe
。
Interesting enough I had to check my interpreter configuration in the project . 足够有趣的是,我不得不检查项目中的解释器配置。 I just assumed that the project would know given the global settings.
我只是假设该项目知道全局设置。 But I guess not.
但我想不是。
Now everything works. 现在一切正常。 Thank you very much everyone.
非常感谢大家。
A few thoughts: 一些想法:
import sys; sys.executable
import sys; sys.executable
to check which is being run. import sys; sys.executable
检查正在运行的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.