Python cannot find dateutil.relativedelta

前端 未结 4 984
抹茶落季
抹茶落季 2021-02-05 01:57

I am trying to run a program using paster serve, but I keep getting the error:

ImportError: No module named dateutil.relativedelta

相关标签:
4条回答
  • 2021-02-05 02:12

    I had a similar issue but for a simpler reason. My fresh virtualenv simply didn't have dateutil installed and I didn't know the Python package name. I tried pip install dateutil, which obviously didn't work since the package name was incorrect. Running pip install python-dateutil instead worked (without resorting to sudo).

    0 讨论(0)
  • 2021-02-05 02:24

    This looks like a problem of package installation to me. A troubleshooting list that comes to my mind:

    1. Verify you installed the package.
    2. If installed, verify that the files have been stored in the right directory (a directory accessible from your python interpreter (= in the PYTHONPATH, useful article here).
    3. Verify permission on those files.
    4. Restart your shell if you tried the import there.
    5. Reboot your computer (ouch... it's 10 years since I started using GNU/Linux, but I still suffer from the bad memories of Windows! ;)
    0 讨论(0)
  • 2021-02-05 02:29

    I also ran into this issue. The simple solution I ended up using was to add --upgrade to the end of the command. This forced it to install it even though Python thought it was installed. This resolved the issue.

    So if you have this issue, try the following:

    sudo pip install python-dateutil --upgrade
    

    It can't possibly hurt anything, so there is no harm in just forcing it to be reinstalled.

    0 讨论(0)
  • 2021-02-05 02:33

    (The previous comment about installing python-dateutil helped me, so perhaps my comment helps someone else).

    For those on Mac OS (v10.6 (Snow Leopard); I am not sure about other versions), the dateutils package is located by default at:

    /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/dateutil
    

    whereas pip install writes the package out to:

    /Library/Python/2.6/site-packages
    

    and does not update the /Library/Python/2.6/site-packages/easy-install.pth file. As a result, when you import dateutil, you will still point to the old location, you can verify this by "import dateutil; dateutil.__file__".

    So what I did (probably better methods are available) was to rename the old directory (/System/Library/.../dateutil) to dateutil.obsolete and restarted Python, then ran the same set of commands again. This doesn't do anything to the path file or sys.path, but skips the old dateutils package so you can get to the new one.

    0 讨论(0)
提交回复
热议问题