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, 2014 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, 2014 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, 2014 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, 2014 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, 2014 at 4:03

7 Answers 7


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)
  • 6
    Thanks but why is this necessary? Breaking python on an upgrade is nasty stuff. Sep 24, 2015 at 4:56
  • 2
    I tried the other answers on this page and they didn't work, but this one did. Oct 27, 2016 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 Ayub
    Jan 30, 2017 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. Jan 30, 2017 at 22:27
  • This also work with virtualenv installations
    – josircg
    Dec 22, 2019 at 17:02

You can just reinitialize the virtualenv by:

virtualenv .
  • 2
    Note that it should be virtualenv . instead of virtualenv , Dec 12, 2014 at 14:41
  • 4
    This answer seems better, than Brandon Rhodes's one.
    – Tim
    Jul 23, 2015 at 10:09
  • If one uses the virtualenvwrapper can do cd $VIRTUAL_ENV.
    – maciek
    May 4, 2016 at 11:54
  • OSError: [Errno 1] Operation not permitted
    – Cerin
    Nov 6, 2017 at 0:29
  • @Cerin, I had the same problem, I just used a sudo virtualenv . to install the new Python executable, and then changed back the whole $VIRTUAL_ENV to the correct directory owner.
    – iMitwe
    Apr 30, 2019 at 7:51

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
  • 10
    I also had to rm -rf /opt/eff.org to make it work Oct 20, 2017 at 11:27
  • 7
    removing /opt/eff.org fixed it Oct 31, 2017 at 18:59
  • 1
    same for me ... /opt/eff.org
    – cljk
    Feb 9, 2018 at 14:26

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? Sep 11, 2014 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .