I am trying to execute a python script that needs img2pdf module.
Note, I already have the Ubuntu package installed for python-img2pdf:
which img2pdf
/usr/bin/img2pdf
Given the following line:
import img2pdf
I get the following:
ModuleNotFoundError: No module named 'img2pdf'
I had only python3.6 version installed before and I have installed python3.9.1 now, After that, I have started getting this error. I think it is something to do with PATH or python default version but after a lot of efforts, I am unable to rectify it.
These are my system details which might help you understand my problem further.
$python -V
Python 3.6.9
$python3 -V
Python 3.9.1
$pip -V
pip 21.0.1 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)
$which python
/usr/bin/python
$which python3
/usr/local/bin/python3
$which pip
/usr/local/bin/pip
Ubuntu 18.04.4
Arm64 arch
Try something like this, I think img2pdf is a shell cmd and cannot be used as a python module ^^
Best regards
deleaf
import os
img2pdf = os.system("img2pdf /path/to/your/image")
https://stackabuse.com/executing-shell-commands-with-python/
Related
There are many questions regarding imaplib2 has no attribute IMAP4_SSL but none of the solutions in the other questions worked for me.
I have a python script that's been running without issue for years on AWS, but after I upgraded to Ubuntu 20.04.2 LTS, it started throwing the error about IMAP4_SSL. After looking into the issue, I believe it may have something to do with the mappings in Python, but it all looks correct to me. I also checked that there are no other Python versions installed that could cause a conflict.
Here are the paths for Python and the imaplib2 package
$ which python3
/usr/bin/python3
$ python3 --version
Python 3.8.5
$ whereis python3
'/usr/bin/python3.8-config'
'/usr/bin/python3'
'/usr/bin/python3.8'
'/usr/lib/python3'
'/usr/lib/python3.8'
'/usr/lib/python3.9'
'/etc/python3'
'/etc/python3.8'
'/usr/local/lib/python3.8'
'/usr/include/python3.8'
'/usr/share/python3'
'/usr/share/man/man1/python3.1.gz'
$ sys.path
''
'/usr/lib/python38.zip'
'/usr/lib/python3.8'
'/usr/lib/python3.8/lib-dynload'
'/home/ubuntu/.local/lib/python3.8/site-packages'
'/usr/local/lib/python3.8/dist-packages'
'/usr/lib/python3/dist-packages'
> import imaplib2
> imaplib2.__file__
'/home/ubuntu/.local/lib/python3.8/site-packages/imaplib2/__init__.py'
The problem is likely that you are using an outdated version of imaplib2 from PyPI. You can install a newer version on Ubuntu using the following command.
sudo apt install python3-imaplib2
(Alternatively, if you are not on Ubuntu, you can always install from source.)
Depending on your PYTHONPATH and the location where you installed the old version of imaplib2, you may also need to uninstall the old version using pip before import imaplib2 will import the right version.
python3 -m pip uninstall imaplib2
I'm currently using mac and whenever, I'm launching the terminal it will show like code below. I tried all the method in stackoverflow but it didnt work, so I'm posting my own. Please help me to fix this. I had tried "sudo apt-get install python3-pip" or "sudo pip3 install virtualenvwrapper". They are all installed
Error Message
Last login: Tue Aug 18 22:33:59 on ttys000
virtualenvwrapper_run_hook:12: no such file or directory: /usr/local/bin/python3
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3 and that PATH is
set properly.
Which python command
/usr/bin/python
Python version command
Python 2.7.16
Which python3 command
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
Python version3 command
Python 3.7.4
pip3 --version command
pip 19.3.1 from /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip (python 3.7)
I have installed the latest version of Python numpy module but when i tried to look for the version of the new numpy module, it still shows me the old version.
sudo pip install 'numpy==1.9.0'
python -c "import numpy; print numpy.__version__"
1.8.2
Here are my Python and pip versions
python --version
Python 2.7.6
pip --version
pip 8.1.2
Am i missing something here?
The version of pip you are using is not associated with the version of Python you're using. pip is installing NumPy into the miniconda distribution (BTW, are you aware that the latest version of NumPy is 1.11.3?), whereas your Python binary is reading its site-packages from elsewhere. To determine this, run
python
at the command prompt, then once in the interpreter run
>>> import sys
>>> print(sys.executable)
>>> from pprint import pprint as pp # makes reading the results easier
>>> pp(sys.path)
sys.executable will tell you which python binary you're running, and the sys.path list will tell you from where Python is importing its packages.
All this being said, you need to point your pip script to the version of Python you're actually using. The easiest way (IMO) is to download get-pip.py, then run either
python get-pip.py
(after changing to the download directory) or
sudo python get-pip.py
depending on whether you're an admin or not. This will install the latest version of pip (currently 9.0.1) and associate it with the version of Python that was used to call the script.
I'm using robotframework for automation. I'm trying to use a method from my python library which needs psutil. The problem is when I execute from the robotframwork it gives error ImportError: No module named psutil but when I execute it with Pycharm I don't get any error. I have installed psutil using pip install psutil . I searched a lot on web but couldn't find any reason for this issue.
My experience with this error was that I had multiple versions of python installed on my ubuntu server 16.04LTS.
My PATH resolved to /usr/local/python -> python 2.7.10 meaning typing python into the commandline I got 2.7.10, but the standard path /usr/bin/python linked to python 2.7.12. The psutil module and others were only installed for version 2.7.10
My resolution was to re-symlink /usr/bin/python to point to my 2.7.10 version:
# Find which python your PATH is pointing at and the version
$ which python
# Returns
/usr/local/bin/python
$ /usr/local/bin/python --version
# Returns
Python 2.7.10
$ /usr/bin/python --version
# Returns
Python 2.7.12
Unlink and relink to correct python version in /usr/bin/python
$ cd /usr/bin
$ sudo unlink python
$ sudo ln -s /usr/local/bin/python python
# check python version points correctly
$ /usr/bin/python --version
# Now correctly returns
Python 2.7.10
P.s. Bear in mind it's still worth checking all your modules are correctly installed now that your environment is pointing at the 1 python version
Could you try setting the PYTHONPATH in your environment or by passing it as an option.
This person had a different issue, but the fix I think will be the same:
setup pythonpath before starting test suite
Cheers,
K
I'm trying to install modules on an alternate version of Python (3.3.0) I have installed on my Mac (OS X 10.7.4). The new version of Python runs OK in the IDLE and also in Terminal:
However, trying to install something relatively trivial like NumPy only installs in the old pre-installed version of Python on my Mac (2.7.1).
Executing this:
$ python3.3 easy_install numpy
Gives me this error message:
/Library/Frameworks/Python.framework/Versions/3.3/Resources/Python.app/Contents/MacOS/Python: can't open file 'easy_install': [Errno 2] No such file or directory
I then read that creating a virtual environment is the way to go, so I tried that:
$ mkvirtualenv python=python3.3 foo
It returned this error:
-bash: mkvirtualenv: command not found
So, I clearly don't have that installed correctly, either (virtualenv-1.8.4).
There is probably lots more homework that I need to do, but I don't really have any intention of using 2.7 ever again, just Python 3 so I don't need to go back and forth. At the same time I know that I need to keep the old version of Python on my Mac for whatever reason, so I don't intend to delete it. Any suggestions for what I'm missing would be very helpful.
Try with this:
easy_install numpy
easy_install is a shell script, not a python script.
I solved this by using Anaconda from Enthought. It had all the plugins and such that I needed. Thanks for everyone's suggestions and help! :)
You have the wrong command. Instead of:
$ python3.3 easy_install numpy
you want:
$ easy_install3 numpy
or even more specific:
$ easy_install-3.3 numpy
But you shouldn't be using easy_install in the first place:
$ pip3 install numpy
or more specific than pip3:
$ pip-3.3 install numpy
If you look deeper, you'll see that both pip3 and pip-3.3 are the same:
$ pip3 --version
pip 1.2.1 from /usr/local/lib/python3.3/site-packages/pip-1.2.1-py3.3.egg (python 3.3)
$ pip-3.3 --version
pip 1.2.1 from /usr/local/lib/python3.3/site-packages/pip-1.2.1-py3.3.egg (python 3.3)
and both easy_install3 and easy_install-3.3 are the same:
$ easy_install3 --version
distribute 0.6.32
$ easy_install-3.3 --version
distribute 0.6.32