Python3: No module named dateutil - python-3.x

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?

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.

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

import distutils.command.bdist_wininst as orig

Everything went well while I was trying to create a ros 2 package in Ubuntu 22.04 by following the ros2 documentation, however when I got to the colcon build step, it failed for python packages even though it works for cMake packages.
colcon build --packages-select mypkgpython
...
import distutils.command.bdist_wininst as orig
ModuleNotFoundError: No module named 'distutils.command.bdist_wininst'
knowing that my python version is:
python3 --version
Python 3.10.6
i have tried:
sudo apt-get install python3-distutils:
python3-distutils is already the newest version (3.10.6-1~22.04).
sudo apt-get install python3-apt:
python3-apt is already the newest version (2.4.0).
sudo apt install python3-colcon-common-extensions
python3-colcon-common-extensions is already the newest version(0.3.0-1)
how can i solve this problem?
i expected when i build my python package using
colcon build package
it will be successfully build, so i could work with
The bdist_wininst command was deprecated in Python 3.8 and you are using python 3.10
Its no more found in python3-distutils package .
use
bdist_wheel (wheel packages) instead
or
if you want to run your code as it is downgrade your python to < 3.8
The bdist_wininst format was deprecated in Python 3.8, and the documentation for this format has been removed in Python 3.9. The recommended way to distribute Python packages now is the Wheel format.
you can overcome this error by JUST updating the setuptools
pip install --upgrade setuptools
Note that: Setuptools version 58.2.0 is the last version that works with ROS 2 python packages without any warnings because it is the last version that supports the old installation method, "python setup.py install." This method has been deprecated and replaced by newer, standards-based tools, such as pip and ament.
pip install setuptools==58.2.0

ModuleNotFoundError: No module named 'harfang'

PLEASE ,how to import harfang in ubunto for python3 ,?? it doesn't install for me !!
i tryed pip install harfang and doesn't work
Solution
The solution is to simply use
pip3 install harfang
or
python3 -m pip install harfang
If it throws error regarding pip not being installed, you can install python3-pip using apt.
Explanation
Why you were unable to install with pip directly and instead had to use pip3 is because, in ubuntu, the default python version is python 2.x. The current python versions actively maintained and supported is 3.x where x means some minor version.
Due to this reason, after you install a python 3.x installation, you need to specify if it's python3 or python2, where python is a default alias for python2.
I also mentioned about python3 -m pip install harfang. This also works, as python3 -m pip means trying to run a python module using specific python installation (which in our case is python3), you can specify which module to call using -m. You can do it with any other installed python module which has a CLI interface as well.

How to install libdoc2testbench on Ubuntu

libdoc2testbench is a tool of Robot Framework which supports importing test results to imbus testbench. Due to Robot Framework documentation, it is to be installed by
pip install robotframework-libdoc2testbench
I want to install it on Ubuntu 18.04; there I get the error:
Could not find a version that satisfies the requirement robotframework-libdoc2testbench (from versions: )
No matching distribution found for robotframework-libdoc2testbench
Best regards
Gerhard
You are probably calling pip from Python 2.7.
Make sure you use Python 3, for example with:
python3 -m pip install robotframework-libdoc2testbench
EDIT: You can download the .wheel or source tar from pypi.org and install with pip pointing to it (and then if needed, download other required packages).
However the solution to your problem is the Python version. From the project page, we see it needs Python 3.7.

Do I have different python versions and which one I am working with?

I am confused about different python versions on my Computer and in Anaconda.
First: I use an iMac (OSX Catalina).I sometimes use the command line (Terminal on my iMac) directly and sometimes I use Anaconda Navigator (for example when I want to work with Jupyter Notebooks).
When I type python3 --version, I get the answer that I have python 3.8.0 installed. But recently, I installed the latest pip version with pip3 --user --upgrade pip. The answer I got was:
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
pip 20.0.2 from /Users/Andrea_5K/Library/Python/3.7/lib/python/site-packages/pip (python 3.7)
I wondered why in this message python 3.7 is referenced.
When I check my Library/Python folder in my user folder I see that I have a 3.7 folder and a 3.8 folder as well. Is there something wrong? Is pip 20.0.2 now installed on python 3.7 although I use python 3.8? And what does the WARNING message mean?

How to delete an installed Module in Python 3.7?

I installed a module with pip in python 3.7(Win 10). However now I have seen that this module gives me problem so I want to delete this installed module.
I installed the module SomePackage with
python -m pip install SomePackage
Now I want to delete "SomePackage" from my Python Environment.
I have tried different ways but they seem to be valid only for earlier versions, i read it has changed from version 3.4
Is there anyway to delete desired module from Python setup?
pip uninstall somepackage
will uninstall the package that you have installed. Look into this answer as well https://stackoverflow.com/a/35524522/4334340

Resources