简体   繁体   中英

How to install Pip on a new Ubuntu upgrade

I posted the question below, but none of the answers I was pointed to worked, though they look like they should.

I activated (again) the virtualenv. It still tells me that pip can't be found by apt when doing an 'apt install' command. But here is where I am now, and very confused.

I pointed my directory to "/home/.../q7root/bin/pip" and did an "ls". It shows a sub-directory with pip in it (or, I think, a link to it - I'm not the best at Unix). When I type "which pip" I get the path to this point ('q7root/pip'). bit if I just type "pip" at the CLI I get I get this error:

[![pip error][1]][1]

I have looked at my PATH, and this q7root/bin is the first place to look on the path. And, despite trying mightily with all the references people gave me, pip3 never gets installed.

But even pip is challenged. "which pip" points to this copy in the virtual environment site, but typing "pip" as a command tells me 'No module named pip.'

So pip seems to need more stuff installed (?), or there is some mess. Any advice?

Original Question:

At the suggestion of others working on what was a functional Django project, I upgraded to a more recent version of Ubuntu (18).
However, when I first try to run it it blows up at line 3 of the initial script module when asked to import django as a package.
I tried pip -r requirements.txt , but the system said pip was an unknown package. I dropped down and used apt to load pip onto my machine ( sudo apt-get pip ), then tried using pip itself ( pip update pip ) which failed.: [![Pip load error message][2]][2] I also tried pip install django , and got this: [![django not found][3]][3] I would have thought an OS upgrade would not require re-installing all currently installed packages (seems like a no-brainer to do the work of installing everything that had been installed). But right now I am terribly stuck...obviously, having 'pip' let's you (at least) have a basic CLI tool. Any advice? [1]: https://i.stack.imgur.com/OPfgc.png [2]: https://i.stack.imgur.com/shLOc.png [3]: https://i.stack.imgur.com/bEhDB.png

It depends on the version of python.

Python 3

sudo apt update
sudo apt install python3-pip

Python 2

sudo apt update
sudo apt install python-pip

How to Install Pip on Ubuntu 18.04

Start with a fresh Ubuntu install. I think you've run too many commands for your current setup to be reproduceable.

Install python3 and python3-venv .

sudo apt update
sudo apt install python3 python3-venv

Use the venv module to create the virtual env.

python3 -m venv myenv
source myenv/bin/activate

You now have access to pip in the venv.

It's OK to upgrade pip in the virtual env, I suggest you don't ever upgrade the system pip otherwise you might hit issues like this .

(myenv) python -m pip --version
(myenv) python -m pip install --upgrade pip

Now you can use pip to install your requirements in the virtual env.

(myenv) python -m pip install -r requirements.txt

In the above commands I've used python -m pip instead of pip . This is the recommended way, as it ensures that you are using the version of pip that matches python .

In the end, this was a state of deep computer confusion. I was already disk-limited so I bought a new computer, and this error did not recur with the same code being used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM