Last Updated: February 25, 2016
·
3.743K
· voylinux

Standard python libraries not importing error in Virtualenv

If you just updated your system and working with some python application in virtualenv, it is possible to get some weird error with standard libraries import like:

ImportError: No module named datetime

Probably some of your python global installations files has changed, so Virtualenv has some broken links.

Solution:

  • From inside your virtualenv, save all the required libraries to a requirements file:
pip freeze > requirements.txt
  • Delete your virtualenv :
rmvirtualenv your_virtualenv_name

-Then create it again with virtualenv wrapper:

mkvirtualenv your_virtualenv_name
  • From inside your virtualenv, reinstall all your application requierements:
pip install -r requirements.txt

You got it!