When I use pip3 I get this error:
Traceback (most recent call last):
File "/Library/Developer/CommandLineTools/usr/bin/pip3", line 7, in <module>
from pip import main
ModuleNotFoundError: No module named 'pip'
I tried to reinstall PIP but still reported this error, but I use python3 -m ensurepip
It told me to install Xcode command line
$ python3 -m ensurepip
$ xcode-select: Failed to locate 'python3.9', requesting installation of command line developer tools.
I had this problem when I was trying to update the pip and it failed.
This always works for me:
Download the script, from https://bootstrap.pypa.io/get-pip.py.
Open a terminal/command prompt, cd to the folder containing the get-pip.py file and run:
python get-pip.py
font: https://pip.pypa.io/en/stable/installation/
Try to install python3.9 as suggested by the terminal.
Related
First of all, sorry about my english, this isn't my native language.
PS C:\Users\...... wsl ./Test.py
Traceback (most recent call last):
File "./Test.py", line 2, in <module>
from PIL import Image
ModuleNotFoundError: No module named 'PIL'
I made this Test.py using pycharm. Its a wordcloud program and it works fine with pycharm.
However, when I try to execute this file with wsl ./ it shows me the error above. Can someone help?
According to your comment you are checking if Pillow is installed in Windows, but you are running your Windows-hosted Test.py in WSL, i.e. using python interpreter and libraries that are installed in WSL.
To illustrate, Powershell session in Windows, using python libpath from conda:
(base) PS C:\> python -c "import os; print(os.__file__)"
C:\Users\ml\Miniconda3\lib\os.py
Powershell session in Windows, but executing code in WSL, python and libpath from Ubuntu:
(base) PS C:\> wsl python3 -c "import os; print(os.__file__)"
/usr/lib/python3.8/os.py
You do need to check your Pillow installation, but in WSL.
You most likely do not have Pillow installed, and the code wants it to run.
To install it you should just need to run
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade Pillow
or you can follow the instructions on the pillow website
Hope that helps [:
Unable to import a python module as a non root that was installed as root.
I have installed flask_babelex package in both ways:
pip3 install --user flask_babelex
pip3 install flask_babelex
and working fine when I try to import:
[root#dev-apache ~]# python3 -c "import flask_babelex"
It's not working if were I run as a non-root user:
[root#dev-apache ~]# su - apache
-bash-4.2$
-bash-4.2$ python3 -c "import flask_babelex"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'flask_babelex'
I tried by changing permission to site-packages but no use:
/usr/local/lib/python3.6/site-packages
any workaround suggestions?
You can ensure you're installing the package with the correct python environment by running
python3 -m pip install flask_babelex
This will install the package specifically in the environment that your python3 is using
I am using ubuntu 18. The default python3 version is 3.6. I updated to 3.7 today and update the alternatives to point to python3.7.
I can use python3.7 by typing python3. I can also use pip3 --version (20.0.2).
I can activate the virtual environment by using pipenv shell. But I cannot install package using pipenv install . It gives me the following error:
pipenv.exceptions.InstallError]: ['Traceback (most recent call last):', ' File "/home/johnchan/.local/share/virtualenvs/src-lkQYyAWf/bin/pip", line 5, in <module>', ' from p
ip._internal.cli.main import main', "ModuleNotFoundError: No module named 'pip'"]
ERROR: ERROR: Package installation failed...
Running which pip3: /usr/local/bin/pip3
Running which pipenv: /usr/local/bin/pipenv
Type pip3 inside pipenv gives:
Traceback (most recent call last):
File "/home/johnchan/.local/share/virtualenvs/src-lkQYyAWf/bin/pip3", line 5, in <module>
from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip'
python2 -m pip install --user --upgrade pip
python3 -m pip install --user --upgrade pip
After upgrading pip (or pip3, in this case) if the following occurs:
$ ~ pip3 -V
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in <module>
from pip._internal import main
ModuleNotFoundError: No module named 'pip._internal'
Force a reinstall of pip:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --force-reinstall
Verify install:
$ ~ pip3 -V
pip 10.0.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
Now pip3 install <package> and pip3 install --user <package> (for user-level installs) will work correctly.
There should never, ever be any reason you need to run pip in elevated mode.
(note: For Python 2.7, just replace python for python3, and pip for pip3)
Had the same issue on macOS as well, it's a common issue across platforms.
I found the answer here:
Setting up a virtualenv: No module named 'pip'
Seems like it is a bug.
I install pipenv using --re flag which is equivalent to virtualenv venv --no-setuptools.
Then I run python get-pip.py inside pipenv.
It works. I can install package now.
But I don't know the reason why...
I tried to make pip3 as the main pip in my Linux by writing this code
alias pip=pip3
and after that what ever command I give to pip, it keeps on giving the same error message:
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
ImportError: cannot import name 'main'
For linux, you can use the argument -m of python bin.
python3 -m pip
so, you can use this allias
alias pip="python3 -m pip"
Use python3 -m pip install --user packagename
I tried to install pip manager using the file get-pip.py as mentioned in the documentation- https://pip.pypa.io/en/stable/installing/
So, I downloaded the file and ran python get-pip.py and as a result, I had permission issues. So I again ran sudo python get-pip.py and it worked.
Now I wanted to install numpy. So I ran pip install numpy and it showed me the Import Error saying-
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in <module>
from pip import main
ImportError: No module named pip
But again when I ran sudo pip install numpy, it worked and got installed. Now, for every python script involving these pip packages, I have to run the script using sudo which I don't like. So how can I resolve these permission issues?
Just to mention-
python v2.7.12
pip v9.0.1
pip installation location- /usr/local/lib/python2.7/dist-packages