58

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.

Thomas Ward
  • 74,764
Joe
  • 681
  • While this is (just) on topic here, you might get a better response on [so]. Also, I can't reproduce it. No errors at all, on the same set-up as you... – Tim Aug 10 '14 at 07: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 07: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 01: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 04:03
  • sudo pip install datetime for those left wondering. – user77510 Aug 29 '14 at 16:45

7 Answers7

89

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)
31

You can just reinitialize the virtualenv by:

cd $VIRTUAL_ENV
virtualenv .
maciek
  • 155
sureshvv
  • 586
30

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
Zanna
  • 70,465
2

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

JBaczuk
  • 241
0

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.

muru
  • 197,895
  • 55
  • 485
  • 740
  • 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
0

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.

Fern Moss
  • 8,785
Doomsday
  • 101
  • 1
0

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
brandizzi
  • 1,562