OS: Ubuntu 14.04 LTS

Python: 2.7.6

My installation of Gourmet Recipe Manager suddenly stopped loading. When I run it in a terminal window, I get the following at the end of the traceback:

import datetime as dt
ImportError: No module named datetime

So far as I can tell, nothing has been changed and my Python installation is up to date. It simply quit working yesterday. I'd certainly appreciate a good approach to diagnose and fix this problem!

Update: thanks to all who replied!

Tim, I'm sorry if I asked this question in the wrong place. Please chalk it up to being a new guy simply following the links from the Ubuntu website.

TheSchwa, I tried your suggestion and got the same error message as above.

muru, the package seems to be installed, but I have no idea if it's installed/configured correctly. How might I find out?

I'm sorry for all the questions, but I'm an old RedHat guy who has been away from Linux for some time. All of the apt/dpkg stuff is new to me.

  • While this is (just) on topic here, you might get a better response on Stack Overflow. Also, I can't reproduce it. No errors at all, on the same set-up as you... – Tim Aug 10 '14 at 7:44
  • What happens if you try import datetime in the python interpreter? You can start the interpreter by opening a terminal and executing python. You can leave it with Ctrl+d. – TheSchwa Aug 10 '14 at 7:58
  • According to dpkg -S $(python -c "import datetime; print datetime.__file__"), the datetime module is from the libpython2.7-stdlib package. Is that package correctly installed? Can you try reinstalling it? – muru Aug 10 '14 at 11:08
  • Okay, so the specific file is /usr/lib/python2.7/lib-dynload/datetime.x86_64-linux-gnu.so do you have that file? Also do you see /usr/lib/python2.7/lib-dynload listed in the output from echo $(python -c "import sys; print sys.path")? Btw the Stack Exchange system doesn't actually notify commenters when you edit your post; so at the very least always post a quick comment such as "Updated question with the info" so we get a notification telling us to check back :) – TheSchwa Aug 12 '14 at 1:04
  • Updated question with the info. Thanks, TheSchwa! My answers are no and yes, respectively. Now, where can I get a new copy of datetime.x86_64-linux.gnu.so? :) – Joe Aug 12 '14 at 4:03

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)
  • 3
    Gosh, thanks a bunch for this. – Anto Dec 1 '14 at 23:29
  • 4
    Thanks but why is this necessary? Breaking python on an upgrade is nasty stuff. – Samantha Atkins Sep 24 '15 at 4:56
  • 1
    I tried the other answers on this page and they didn't work, but this one did. – Michael Terry Oct 27 '16 at 17:32
  • 2
    Got cp: '/usr/bin/python2.7' and '/usr/bin/python2.7' are the same file but the error still exists – Umair Jan 30 '17 at 22:19
  • @Umair There might be something wrong with your activate script, in that case — normally, after activation, which python2.7 will show the path to the environment's Python, not return the path to the system Python. – Brandon Rhodes Jan 30 '17 at 22:27

If you're getting this trying to use letsencrypt after an upgrade, this solution worked for me letsencrypt forums - Can't use auto import: error: no module named io/2345/3

I just had to delete this:

rm ~/.local/share/letsencrypt -R
  • 6
    I also had to rm -rf /opt/eff.org to make it work – CharlyDelta Oct 20 '17 at 11:27
  • 6
    removing /opt/eff.org fixed it – Margus Pala Oct 31 '17 at 18:59
  • 1
    same for me ... /opt/eff.org – cljk Feb 9 at 14:26

You can just reinitialize the virtualenv by:

cd $VIRTUAL_ENV
virtualenv .
  • 2
    Note that it should be virtualenv . instead of virtualenv , – icyrock.com Dec 12 '14 at 14:41
  • 4
    This answer seems better, than Brandon Rhodes's one. – azurkin Jul 23 '15 at 10:09
  • If one uses the virtualenvwrapper can do cd $VIRTUAL_ENV. – maciek May 4 '16 at 11:54
  • OSError: [Errno 1] Operation not permitted – Cerin Nov 6 '17 at 0:29

I had the same problem and finally decided it must be the AWS CLI because I noticed that it had it's own python directory. So I uninstalled AWS CLI and reinstalled it and that fixed the problem:

sudo pip uninstall awscli

sudo pip install awscli

As i found some changes in 14.04 so you need do this from root:

For datetime only:


ln -s /usr/lib/python2.7/lib-dynload/datetime.x86_64-linux-gnu.so                      /usr/lib/python2.7/lib-dynload/datetime.so

For all modules:


ln -s /usr/lib/python2.7/lib-dynload/audioop.x86_64-linux-gnu.so                       /usr/lib/python2.7/lib-dynload/audioop.so
ln -s /usr/lib/python2.7/lib-dynload/_bsddb.x86_64-linux-gnu.so                        /usr/lib/python2.7/lib-dynload/_bsddb.so
ln -s /usr/lib/python2.7/lib-dynload/bz2.x86_64-linux-gnu.so                           /usr/lib/python2.7/lib-dynload/bz2.so
ln -s /usr/lib/python2.7/lib-dynload/_codecs_cn.x86_64-linux-gnu.so                    /usr/lib/python2.7/lib-dynload/_codecs_cn.so
ln -s /usr/lib/python2.7/lib-dynload/_codecs_hk.x86_64-linux-gnu.so                    /usr/lib/python2.7/lib-dynload/_codecs_hk.so
ln -s /usr/lib/python2.7/lib-dynload/_codecs_iso2022.x86_64-linux-gnu.so               /usr/lib/python2.7/lib-dynload/_codecs_iso2022.so
ln -s /usr/lib/python2.7/lib-dynload/_codecs_jp.x86_64-linux-gnu.so                    /usr/lib/python2.7/lib-dynload/_codecs_jp.so
ln -s /usr/lib/python2.7/lib-dynload/_codecs_kr.x86_64-linux-gnu.so                    /usr/lib/python2.7/lib-dynload/_codecs_kr.so
ln -s /usr/lib/python2.7/lib-dynload/_codecs_tw.x86_64-linux-gnu.so                    /usr/lib/python2.7/lib-dynload/_codecs_tw.so
ln -s /usr/lib/python2.7/lib-dynload/crypt.x86_64-linux-gnu.so                         /usr/lib/python2.7/lib-dynload/crypt.so
ln -s /usr/lib/python2.7/lib-dynload/_csv.x86_64-linux-gnu.so                          /usr/lib/python2.7/lib-dynload/_csv.so
ln -s /usr/lib/python2.7/lib-dynload/_ctypes_test.x86_64-linux-gnu.so                  /usr/lib/python2.7/lib-dynload/_ctypes_test.so
ln -s /usr/lib/python2.7/lib-dynload/_ctypes.x86_64-linux-gnu.so                       /usr/lib/python2.7/lib-dynload/_ctypes.so
ln -s /usr/lib/python2.7/lib-dynload/_curses_panel.x86_64-linux-gnu.so                 /usr/lib/python2.7/lib-dynload/_curses_panel.so
ln -s /usr/lib/python2.7/lib-dynload/_curses.x86_64-linux-gnu.so                       /usr/lib/python2.7/lib-dynload/_curses.so
ln -s /usr/lib/python2.7/lib-dynload/datetime.x86_64-linux-gnu.so                      /usr/lib/python2.7/lib-dynload/datetime.so
ln -s /usr/lib/python2.7/lib-dynload/dbm.x86_64-linux-gnu.so                           /usr/lib/python2.7/lib-dynload/dbm.so
ln -s /usr/lib/python2.7/lib-dynload/_elementtree.x86_64-linux-gnu.so                  /usr/lib/python2.7/lib-dynload/_elementtree.so
ln -s /usr/lib/python2.7/lib-dynload/fpectl.x86_64-linux-gnu.so                        /usr/lib/python2.7/lib-dynload/fpectl.so
ln -s /usr/lib/python2.7/lib-dynload/future_builtins.x86_64-linux-gnu.so               /usr/lib/python2.7/lib-dynload/future_builtins.so
ln -s /usr/lib/python2.7/lib-dynload/_hashlib.x86_64-linux-gnu.so                      /usr/lib/python2.7/lib-dynload/_hashlib.so
ln -s /usr/lib/python2.7/lib-dynload/_hotshot.x86_64-linux-gnu.so                      /usr/lib/python2.7/lib-dynload/_hotshot.so
ln -s /usr/lib/python2.7/lib-dynload/_json.x86_64-linux-gnu.so                         /usr/lib/python2.7/lib-dynload/_json.so
ln -s /usr/lib/python2.7/lib-dynload/linuxaudiodev.x86_64-linux-gnu.so                 /usr/lib/python2.7/lib-dynload/linuxaudiodev.so
ln -s /usr/lib/python2.7/lib-dynload/_lsprof.x86_64-linux-gnu.so                       /usr/lib/python2.7/lib-dynload/_lsprof.so
ln -s /usr/lib/python2.7/lib-dynload/mmap.x86_64-linux-gnu.so                          /usr/lib/python2.7/lib-dynload/mmap.so
ln -s /usr/lib/python2.7/lib-dynload/_multibytecodec.x86_64-linux-gnu.so               /usr/lib/python2.7/lib-dynload/_multibytecodec.so
ln -s /usr/lib/python2.7/lib-dynload/_multiprocessing.x86_64-linux-gnu.so              /usr/lib/python2.7/lib-dynload/_multiprocessing.so
ln -s /usr/lib/python2.7/lib-dynload/nis.x86_64-linux-gnu.so                           /usr/lib/python2.7/lib-dynload/nis.so
ln -s /usr/lib/python2.7/lib-dynload/ossaudiodev.x86_64-linux-gnu.so                   /usr/lib/python2.7/lib-dynload/ossaudiodev.so
ln -s /usr/lib/python2.7/lib-dynload/parser.x86_64-linux-gnu.so                        /usr/lib/python2.7/lib-dynload/parser.so
ln -s /usr/lib/python2.7/lib-dynload/pyexpat.x86_64-linux-gnu.so                       /usr/lib/python2.7/lib-dynload/pyexpat.so
ln -s /usr/lib/python2.7/lib-dynload/readline.x86_64-linux-gnu.so                      /usr/lib/python2.7/lib-dynload/readline.so
ln -s /usr/lib/python2.7/lib-dynload/resource.x86_64-linux-gnu.so                      /usr/lib/python2.7/lib-dynload/resource.so
ln -s /usr/lib/python2.7/lib-dynload/_sqlite3.x86_64-linux-gnu.so                      /usr/lib/python2.7/lib-dynload/_sqlite3.so
ln -s /usr/lib/python2.7/lib-dynload/_ssl.x86_64-linux-gnu.so                          /usr/lib/python2.7/lib-dynload/_ssl.so
ln -s /usr/lib/python2.7/lib-dynload/termios.x86_64-linux-gnu.so                       /usr/lib/python2.7/lib-dynload/termios.so
ln -s /usr/lib/python2.7/lib-dynload/_testcapi.x86_64-linux-gnu.so                     /usr/lib/python2.7/lib-dynload/_testcapi.so

Also if you use virtual env copy

cp $(which python2.7) /opt/graphite/bin/python

to your env.

  • 3
    I upgraded to 14.04 and didn't need to do any symlink. Could you provide any evidence that messing the system libs like this is necessary and can't be avoided? – Andrea Lazzarotto Sep 11 '14 at 22:13

I got the error when I upgraded from Ubuntu 14.04 to 14.10. I recreated my virtualenv and the issue went away. So if you're working with a virtualenv, you should recreate it.

However if you don't, I suppose that reinstalling your project will work. Don't touch any system libraries! It can work for the time being, but will potentially lead to issues with others.

This happens after some Ubuntu upgrades. My favorite solution is

$ virtualenv --no-site-packages path/to/virtualenv/dir

This updates everything needed without removing the packages already installed.

If you have many virtualenvs to update, you can use xargs:

$ ls ~/directory/with/virtualenvs | xargs -L1 virtualenv --no-site-packages

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.