Вопрос

I installed the pytz package on my windows7 machine via:

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:

 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:

>>>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. It can't find the package.

I would kindly appreciate some help. Thank you.

*EDIT *

The contents of 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. This time it installed and I can import pytz without the error reported earlier (why would this fix the issue?).

HOWEVER, my ecplise/pydev still does not seem to acknowledge the import pytz statement. It can't resolve it. It also can't resolve import sqlalchemy but the dos python interpreter can import both. The python interpreter in eclipse/pydev is set to C:\Python27\python.exe if you go to Windows > Preferences > Interpreter - Python.

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:

  1. Check that your egg doesn't have any funky permissions set on it.
  2. Is that your only Python install in C? import sys; sys.executable to check which is being run.
  3. Do you have other eggs that you are able to import?
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top