I want to install tensorflow-cpu using pip on my Ubuntu 18.04, 64-bit system and it required pip>=19.0.
I was having pip 9.0.x and was using pip3 to install packages but to fulfill the requirement I ran
pip3 install pip
which installed pip 19.2.3 but after doing it I can no longer use pip3. Using pip3 now gives this error
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
ImportError: cannot import name 'main'
Earlier using pip would give this error
Command 'pip' not found, but can be installed with:
sudo apt install python-pip
but now using it to install packages works totally fine.
I read a lot of articles after which I realised that we use pip for python 2.x and for python 3.x we use pip3. But with the change in behaviour after upgrading pip I'm totally confused and can't find any help. Is using pip to install a package same as installing it using pip3. What are the differences between them?
Related
It seems like I messed up the system pip by pip3 install --upgrade pip. Actually I even do not exactly remember whether I did upgrade or not.
Now when I try to use pip3, it gives an error like
Traceback (most recent call last):
File "/Applications/Xcode.app/Contents/Developer/usr/bin/pip3", line 6, in <module>
from pip._internal import main
ImportError: cannot import name 'main' from 'pip._internal' (unknown location)
I tried sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall to revert back PIP by this answer, but it fails.
/Applications/Xcode.app/Contents/Developer/usr/bin/python3: No module named pip.__main__; 'pip' is a package and cannot be directly executed
which pip3 gives /usr/bin/pip3
Now I am trying to revert back the system tools and use virtual environment.
What should I do? I can't even check which pip version is installed at the moment.
Thanks in advance.
I'm using Python 3.8(64-bit)
Basically, I tried every possible solution on the internet like update the python version and tensorflow version etc.
But when I try to do this:
import tensorflow_quantum as tfq
terminal always say:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'tensorflow_quantum'
Does anyone have any idea on this issue? Cheers
Please run the following:
pip3 install --upgrade pip
pip3 install tensorflow==2.3.1
pip3 install -U tensorflow-quantum
I have faced quite a similar problem and I followed this link for some help
in short I created a virtual environment with
python version == 3.6.2
conda create -n your_new_env_name python=3.6.2 anaconda
and then activated this environment as follows before you continue
conda activate your_new_env_name
then installed tensorflow
pip install tensorflow==2.1.0
pip install tensorflow-gpu=2.0.0
pip install tensorflow-quantum
you may face 2 errors which you might need to be solved
the first is this
When importing tensorflow, I get the following error:
No module named 'numpy.core._multiarray_umath'
all you have to do is this
pip install numpy --upgrade
or if needed
pip install numpy --upgrade --user
you may also get an error when import tensorflow-quantum that's related to google.api_core and what solved the problem for me was to do the following
pip install google.api_core==1.16.0
you may also need to the following
pip install cython
I hope it works!
When installing python modules, I seem to have two possible command line commands to do so.
pip install {module}
and
py -{version} -m pip install {module}
I suppose this can be helpful for selecting which version of python has installed which modules? But there's rarely a case where I wouldn't want a module installed for all possible versions.
Also the former method seems to have a pesky habit of being out-of-date no matter how many times I call:
pip install pip --upgrade
So are these separate? Does the former just call the latest version of the latter?
TLDR: Prefer ... -m pip to always install modules for a specific Python version/environment.
The pip command executes the equivalent of ... -m pip. However, bare pip does not allow to select which Python version/environment to install to – the first match in your executable search path is selected. This may be the most recent Python installation, a virtual environment, or any other Python installation.
Use the ... -m pip variant in order to select the Python version/environment for which to install a module.
So the pip install module is callable if you have already installed the pip. The pip install pip --upgrade upgrades the pip and if you replace the pip into a module name it will upgrade that module to the most recent one. the py -{version} -m pip install {module} is callable if you have installed many versions of python - for example most of the Linux servers got installed python 2, so when you install the Python 3, and you want to install a module to version 3, you will have to call that command.
On Ubuntu 20.04 i have installed pip3 with the following command:
sudo apt install python3-pip
But when I run pip3 I get the following error:
Traceback (most recent call last):
File "/usr/bin/pip3", line 6, in <module>
from pkg_resources import load_entry_point
File "/usr/local/lib/python3.8/dist-packages/pkg_resources.py", line 1479, in <module>
register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'
In a virtual-environment the pip3 command works fine however.
As suggested in other SO answers I have tried reinstalling python3 and pip3, all without success. A lot of other answers use pip3 to solve the problem, but I'm unable to run pip3.
I have noticed that several other programs (docker-compose, Guake) give me a similar error.
I run python 3.8.2. And when I open an virtual-environment I can see that my pip3 version is 20.0.2.
I came a long way to fixing this, but in the end I went with a fresh install. I'll share here what I learned, hoping it can help somebody else.
My hypothesis is that it went wrong when I accidentaly installed a requirements.txt without being in an virtual environment. That triggered the installation of an old setuptools, which then broke pip and ruined everything.
Possible fix could be:
Remove pip: sudo apt-get --purge autoremove python3-pip
Install pip via python: python3.8 -m pip install --upgrade --force-reinstall pip. Now pip works again.
Now try to fix setuptools: pip install --upgrade --ignore-installed setuptools. Fix the issues that pop here (how? don't know). An issue I had here was that I was not allowed to call pip with sudo.
In the end I guess you'll want pip installed the normal way, so you uninstall python3.8 -m pip uninstall pip and install sudo apt install python3-pip
Next time I'll skip installing python3-pip completely. That way I'm forced to open a virtual environment.
In the end, several issues starting popping up (also because I tinkered around a lot) and I just lost faith in my installation. Even if I would fix it all, I knew that when the next issue would pop up I would again feel like this might be the problem. Better to start fresh and have a solid base.
Using Ubuntu 16.04 with Python 3.5 I get import errors for some packages, e.g. 'BeautifulSoup4' or 'requests'. Both libraries are installed from the Ubuntu repositories:
$ dpkg --get-selections | grep -E "python3-req|python3-bs"
python3-bs4 install
python3-requests install
Yet I get "ImportError: no module named 'bs4'/'requests'".
$ python3 -c "import bs4"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named 'bs4'
Only when I (additionally!) install those libraries via pip3 it works. The documentation of BeautifulSoup says to install it as "python3-bs4" via apt. Why does it only work with the pip3 method? What's the purpose of the python3-bs4/python3-requests packages?
I was able to resolve the issue.
I'm still not quite sure what was the exact problem, but I suspect that pip3 and apt confused each other about what was actually installed. pip3 also listed several python packages which were installed via apt.
I removed/purged everything via apt that was recognized by pip3 list and also purged pip3. Then I apt install --reinstall the packages that gave me trouble previously: python3-bs4 and python3-requests. The requests library still didn't work because it missed the packages python3-six, python3-chardet and python3-urllib3 which where reported as already installed by apt. A apt install --reinstall fixed this as well. And then it worked!