Home > other >  Python3: No module named dateutil
Python3: No module named dateutil

Time:01-08

I am unable to get dateutil installed in my Python code.

    from dateutil import tz 
ImportError: No module named dateutil

I had date-util installed (Python version is 3.7.3)

> pip3 install python-dateutil
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: python-dateutil in /usr/lib/python3/dist-packages (2.7.3)

I cannot uninstall them (to reinstall). I get the following error

> sudo pip3 uninstall python-dateutil
Not uninstalling python-dateutil at /usr/lib/python3/dist-packages, outside environment /usr
Can't uninstall 'python-dateutil'. No files were found to uninstall.

Then, I used the following command to uninstall:

> sudo apt-get remove  python3-dateutil #This worked
> pip3 install python-dateutil 

This works, but asks me to install cycler, kiwisolver, pyparsing, which I install using pip3. But I still cant get the python code working - has the same error (ImportError: No module named dateutil)

Any suggestions on what's going on?

CodePudding user response:

I found a solution - The python code is being called from a bash script. It worked fine until recently. Recently I installed some other packages that installed python 2.x. So, the python scripts were using Python 2.x rather than 3.x. I had symbolic links to python 3.x, but that didn't help.

Now, I am explicitly use python3 mycode.py to overcome this issue.

CodePudding user response:

I highly recommend to use conda environment instead of pip. See, there are several modules which do not give expected behaviour in pip (like pytorch).

Get the package installed using:

conda install -c conda-forge python-dateutil

returning the question, to get the package running it requires fulfillment of it's dependencies. If you are using python 3.7.3 its obvious that it may lack in some of the features of modern python 3.11 as a result you get the obvious error. The python package python-dateutil must have been configured according to the modern python language version.
Iam using python 3.11.1 and the package gets installed very perfectly. You may install old version of package or upgrade your python language version or use Conda as mentioned before.

  • Related