Pip: unable to install a package
Solved5 answers
Hey!
Have you seen the latest lines in your CMD? (access denied -> lack of rights & for pip, it gives you the command for the upgrade).
Ainoa.
Hello
Do you really need Python 3.6?
We're at 3.12 now, with the proper pip.
When I was little, the Dead Sea was just sick.
George Burns
Hello,
Short answer
The pip package you are trying to update is deployed in the system folders (not your user folder). Therefore, you cannot update it with a user profile (which does not have sufficient rights); you need to update it with administrative rights (see #1 and #5).
Other possible approaches consist of deploying pip:
- either in your user folder;
- or in a virtual environment.
Detailed answer
You need to understand that you can have multiple Python environments in which to install a package:
- at the system level (modifiable only by the administrator)
- at the user folder level
- in a virtual environment (I will return to this later).
These environments are not exclusive: a single package can, in theory, be installed in all of these places. And pip is no exception, as it is itself a package.
The question now is where the package {must be|is} installed. If the relevant environment is the system, root rights are required. Otherwise, user rights are sufficient. In #3 you are apparently trying, with user rights, to intervene on a package deployed with administrative rights. You therefore have insufficient rights, hence the error.
Installing pip in the user folder
As I mentioned in the previous section, nothing prevents you from installing pip in both system folders and the user folder. In this case, the user pip should take precedence over the administrator pip. To be convinced, just look at your PATH environment variable. This can be useful when you are not an administrator on your machine, but you need a different version of pip as a user.
Using pip: as a user or administrator?
Regardless of where pip is installed, the context in which you call pip is decisive, as it will determine which environment you are going to operate in:
- If you use your user profile and you run a pip install (respectively pip install -U, respectively pip remove), then you are trying to deploy (respectively update, respectively remove) the package in your user folder;
- If you use your administrator profile and you run a pip install (respectively pip install -U, respectively pip remove), then you are trying to deploy (respectively update, respectively remove) the package in the system folders. And in this case, only the administrator can intervene on this package.
To go further: virtual environments
Virtual environments (virtual environment in English, often abbreviated to venv) are the classic way (and proposed by PyCharm) to free a project from any packages installed in the user folder or in system folders (including pip).
- Advantages:
- The project is completely isolated and therefore insensitive to what happens in the system and user folders (installed packages + version).
- It ensures that all the dependencies of the project are well defined.
- Disadvantages:
- You need to have determined all the dependencies of the project (in a project, they are often listed in requirements.txt or pyproject.toml).
- Each time you want to use the project, you need to activate this virtual environment (unless the dependencies are also deployed in the system and/or user folder).
- Even if these dependencies are already installed in the user and/or system folder, they will be reinstalled in the virtual environment, which ultimately consumes more disk space.
Good luck