Python神奇的错误

2019-02-23  本文已影响0人  qboy0000

ImportError: No module named datetime

近日把服务器给用apt upgrade了一下,而virtualenv创建的工作env目录下的使用时会报一处神奇的错误

ImportError: No module named datetime

一开始知道啥问题,毕竟datetime是python环境自带的,不应该datetime这个包都没有啊?我以为是工作环境发生了变化,利用

import sys
sys.path

发现python的搜索路径是没有变化,所以不应该是这个问题,
bing之后,注某度搜索出来的都是答非所问。
查到
https://askubuntu.com/questions/509283/python-no-module-named-datetime
里面有一个热心网友回答如下:

This just happened to me after the 14.10 update, and it seems to be because my virtual environments have old copies of /usr/bin/python2.7 that — unlike the new binary — do not include datetime built-in, and so get an error when they cannot find it on disk anywhere. The new interpreter seems to import it without any file I/O (try running it under strace to check).

I fixed each virtual environment by activating it and running:

$ cp /usr/bin/python2.7 $(which python2.7)

按照其方法将/usr/bin/python2.7 复制到每一个虚拟环境中即 env/bin/目录下即可以了。如果该目录下的python正在被使用,还得先把python进程 kill掉。

上一篇 下一篇

猜你喜欢

热点阅读