2

I'm using Visual Studio Code to write a small script and part of it involves using dateutil to parse a string and see if a date exists. Very straight forward, but for some reason, import dateutil just doesn't work.

I've read around and I've tried every suggestion I've ran into

  • Making sure that pip -V and python -V correspond with the correct version of Python (Pip is v.3.10 and Python is v.3.10.5)

  • Uninstalling and reinstalling dateutil via pip uninstall python-dateutil and pip install python-dateutil. Tried both pip install python-dateutil AND pip3 install python-dateutil after I uninstalled and neither works.

  • Doing all that AND restarting the IDE

  • Double checked to see if pip was added to my PATH variable properly (it is; echo %PATH% shows the correct directories)

I'm not sure why this is happening or what else I can try to do to resolve it

Daniel Trugman
  • 8,186
  • 20
  • 41
vQuiche
  • 23
  • 1
  • 5
  • Can you show pip logs? – Yohann Boniface Jun 14 '22 at 23:00
  • Are you installing the module to the same virtualenv that you are using to run? – jordanm Jun 14 '22 at 23:01
  • Can you show us the traceback? You don't have a local file called "dateutil.py", do you? – Tim Roberts Jun 14 '22 at 23:01
  • What do you mean "doesn't work"? *What happens* when you try to `import dateutil`? If there is an error, please show a [complete](https://meta.stackoverflow.com/questions/359146) error traceback. – Karl Knechtel Jun 14 '22 at 23:07
  • Just because `pip` uses the same numbered *version* of Python, doesn't mean it's using the same *installation*. This is one reason why `python -m pip` is recommended. That said, your IDE could use a different installation from the one that you get using `python` on the command line, too. People have all kinds of strange installation setups out there, and there's no way we can just guess what's on your system. – Karl Knechtel Jun 14 '22 at 23:10
  • [Download](https://pypi.org/project/python-dateutil/#files) the `.whl` file and install the module from that. – martineau Jun 14 '22 at 23:18

1 Answers1

0

I have had this error a couple of times the last months. For me, the issue has been connected to the Python interpreter in use (I believe this is only an issue if you are using a virtual environment)

The solution has been to replace the venv interpreter (recommended) with the global interpreter of the same version. Please see my answer to a similar thread for instructions/screenshots

Anna Madsen
  • 384
  • 3
  • 15