簡體   English   中英

導入錯誤:使用easy_install后沒有名為pytz的模塊

[英]Import Error: No module named pytz after using easy_install

今天是我在Python的第一天,一直在經歷問題。 我正在研究的是“編寫一個簡短的程序,從操作系統中提取當前的日期和時間,然后按照以下格式將其打印在屏幕上:日,月,年,格林威治標准時間的當前時間。證明它有效。 “

我打算使用pytz,所以使用easy_install pytz將它安裝在我的site-packages中(pytz-2012d-py2.7.egg)

這是我能夠導入模塊的正確目錄嗎?

在我的python shell中,我使用pytz導入時區我得到, "ImportError: No module named pytz"

有任何想法嗎? 提前致謝

time模塊也可以在這里幫助.. UTC是協調世界時(以前稱為格林威治標准時間,或GMT)

In [18]: import time

In [19]: time.gmtime()
Out[19]: time.struct_time(tm_year=2012, tm_mon=9, tm_mday=22, tm_hour=3, tm_min=37, tm_sec=15, tm_wday=5, tm_yday=266, tm_isdst=0)

In [20]: x = time.gmtime()

In [21]: x.tm_year
Out[21]: 2012

In [22]: x.tm_mon
Out[22]: 9

In [23]: x.tm_mday
Out[23]: 22

In [24]: x.tm_hour
Out[24]: 3

你也可以在安裝下面的pytz的同時檢查日志......

C:\>easy_install 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 2012d
Downloading http://pypi.python.org/packages/2.7/p/pytz/pytz-2012d-py2.7.egg#md5=
e6f9219ae6eff242f13c6700413df69e
Processing pytz-2012d-py2.7.egg
Moving pytz-2012d-py2.7.egg to c:\python27\lib\site-packages
Adding pytz 2012d to easy-install.pth file

Installed c:\python27\lib\site-packages\pytz-2012d-py2.7.egg
Processing dependencies for pytz
Finished processing dependencies for pytz

C:\>python
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pytz
>>> from datetime import datetime, timedelta
>>> utc = pytz.utc
>>> utc.zone
'UTC'

對於它的價值,這里的基本問題的答案是pytz安裝過程實際上沒有提取“.egg”文件(至少,這是我注意到的非常類似的問題。)

您可以考慮進入site-packages文件夾並自行解壓縮。

如果你使用python v2或python v3很重要 - 它有單獨的easy_install包! 在debian中有:python-pip python3-pip

然后easy_install easy_install3

如果您使用錯誤版本的easy_install,您將更新錯誤的庫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM