Pip won't install packages in virtualenv - python

After performing a system upgrade this morning, I'm not able to install or update packages in any of my old or fresh created virtual environments.
I create the virtual environments using virtualenvwrapper.
I've tried rebooting my PC, recreating all of my virtual environments, but nothing worked.
Strange enough, pip freeze does not output my installed packages, although they are found in sitepackages.
Im using python3.7 on manjaro linux with the newest kernel.
In my envs and on my system pip 19.2.3 is installed.
The error I'm seeing is the following:
pip install <package>
ERROR: Can not perform a '--user' install. User site-packages are not visible in this virtualenv.
When trying to use the system pip without virtualenv, everything works just fine.
pip install cython
Requirement already satisfied: cython in /home/manuel/.local/lib/python3.7/site-packages (0.29.13
I expect pip to install the desired package to the sitepackages folder of my virtualenv without telling me to not use a '--user' install, which I'm not doing explicitly anyway

I was able to fix this myself.
I checked all the pip config files here https://pip.pypa.io/en/latest/user_guide/#configuration
Seems like in the pip configuration file /etc/pip.conf the user parameter was set to true.
Changing it to false resolved my issue.
I still don't know why/if the config file changed.

Related

Can't upgrade pip in windows [duplicate]

On Windows, if you try to use pip to upgrade itself, inside a virtualenv, you may get a mysterious "access is denied" error. For instance:
D:\scratch\> C:\Program Files\Python\3.7.4\x64\python.exe -m venv D:\scratch\my-venv
D:\scratch\> D:\scratch\my-venv\Scripts\activate
(my-venv) D:\scratch\> pip install --upgrade pip
Collecting pip
Downloading pip-19.3.1-py2.py3-none-any.whl (1.4MB)
Installing collected packages: pip
Found existing installation: pip 19.0.3
Uninstalling pip-19.0.3:
Could not install packages due to an EnvironmentError:
[WinError 5] Access is denied: 'd:\\scratch\\my-venv\\scripts\\pip.exe'
Consider using the `--user` option or check the permissions.
This happens whether or not the command prompt has administrative privileges.
We know we have write access to everything inside d:\scratch\my-venv, because we just created it with the initial python -m venv command. The advice to use the --user option is unhelpful, since we want to upgrade the version of pip inside the virtualenv, which --user will not do.
What could be wrong, and what is the correct way to upgrade pip inside a virtualenv on Windows?
I don't know if this is the only reason this can happen, but notice that the "Access is denied" error points at d:\scratch\my-venv\scripts\pip.exe. pip is trying to replace itself, and Windows doesn't allow you to modify a running EXE file in any way.
A workaround for this specific problem is to use python -m pip install --upgrade pip instead. This way, pip.exe is not running, so Windows will allow it to be replaced. This action doesn't try to overwrite d:\scratch\my-venv\scripts\python.exe, and Windows doesn't care what pip does to all the other files belonging to the pip package.
See https://github.com/pypa/pip/issues/188 and https://github.com/pypa/pip/issues/1299 for further information.
You must have the same version of pip installed in windows as in the virtual env. I think that is the reason for the error Access Denied in Virtual Env.
in promt,
python -m pip install --upgrade pip
located in the Scripts folder of the virtual env, execute the update command upgrade pip in venv
I would have put this in a comment to zwol's answer, but I don't have enough reputation yet.
I just wanted to add to anyone else potentially coming across this from google like I did, that python -m pip install --upgrade pip did fix this issue for me. However if you try pip install --upgrade pip before doing that, something happens in the process before you hit the access denied error that messes up pip. I personally was getting ModuleNotFoundError: No module named 'pip' after trying to upgrade the normal way.
Once I deleted and restarted my virtualenv and had the first command be python -m pip install --upgrade pip It worked just fine.
I hope that helps other newbies out there struggling like me! :)
Same error for me, but in both conditions: my system pip and virtualenv pip. So, when I tried to upgrade my system pip, hopefully it wasn't like totally deleted, I could still use the "pip" command. However I know the upgrade system pip failed. When I tried the command again, it said pip was on the latest version. Maybe this is just a glitch. I believe it is the same for virtual environments(virtualenv, venv). When I upgrade the system pip I get this error:
ERROR: Could not install packages due to an OSError: [WinError 5] Access is denied: 'C:\\Users\\heewo\\AppData\\Local\\Temp\\pip-uninstall-8ob_krif\\pip.exe'
Consider using the `--user` option or check the permissions.
I know this is not normal. But still, different than the virtualenv, "pip" is still installed. I believe this is still ignorable as this is just a known issue and most people here know about this topic. For me, python -m pip install --upgrade pip did not work in this state.
I tried this method, and this did work for me.
virtualenv --pip [VERSION]
and replace VERSION with the latest version available on pip. This prints out that what version you are attempting to upgrade to, when you get the error.
And that should do the trick.

Scripts folder installs empty python 3.10.3

So im pretty new to python and i need pip for something i wanna do, but everytime i install python the Scripts folder where pip should be always installs empty. I make sure that install pip is checked when downloading python. How do I get it to install pip with python?
If you installed Python, it came bundled with pip.
The default packages:
C:\Users\<Your username>\AppData\Local\Programs\Python\Python310\Lib\site-packages
A better practice is to install a venv for every project you are working on. Every venv will have its own set of dependencies(i.e. packages), and it will be easier to manage them.
You can find installed packages in your venv:
YOUR_PROJECT_PATH\venv\Lib\site-packages
EDIT
From official docs:
Pip not installed¶ It is possible that pip does not get installed by default. One potential fix is:
python -m ensurepip --default-pip
There are also additional resources
for Installing pip

Django pip freeze > requirements.txt not getting the exact packages installed in the virtual env

Django pip freeze > requirements.txt not getting the exact packages installed in the virtual env rather it's getting all the packages i have ever installed and it's kinda not what i exactly wants, let me show some image of whats happening
there are still more packages below, please what can i do
Whenever you do
pip freeze
It prints out all the installed packages. May be you are confusing with packages installed as dependency of manually installed packages.
For example if you install Fastapi, it will also install jinja2
I can't think of any case where you want packages installed by you and not their dependencies. Its not a problem at all.
On the other hand if its actually giving you all the packages ever installed, it means you have installed all your packages in the same environment always. You should use different environments for each of your project (sometimes even more than one for a single project). In this case, create another virtual environment, install requirements and then again use pip freeze. Steps below.
python3 -m venv venv
source venv/bin/activate
pip install {required packages}
pip freeze > requirements.txt

pip has to reinstall all packages in exported virtualenv

I have a question about python virtualenv. I get a virtualenv for a project with all packages required to run that project. But when i run it for the first time and it crash 'cause python has some requirements not satisfied. So i check if there is all packages inside:
virtualenv/lib/python2.7/site-packages/
and all packages required are inside.
But when i type:
pip list
packages doesn't shown. So i have to run:
pip install -r requirements.txt
pip downloads them again.
So my question is, why pip downloads and reinstall them again if they are installed yet ? And how i can force pip to reinstall all packages inside virtualenv ?
The problem was that all scripts inside the virtualenv were created on another pc with them paths. Indeed when i launched python or pip from virtualenv they ran from my global path 'cause couldn't find virtualenv script path and in particular pip shown my global packages.
Fixing directives path of all script inside virtualenb/bin/ to my real virtualenv path solved this issue.

pip installs packages, but doesn't mark them as executable, so python doesn't find them

I've been trying to use sudo to install python packages on a system that I am on the sudoers list, but don't have general root access (i.e. don't have the password for su). I can install packages, for example
sudo pip install django
however when I try and use them python simply claims not to have the package installed. Investigating the contents of /usr/lib/python it appears that other packages directories and .eggs have executable permissions for ugo, however the packages I install using sudo pip do not have this permission. Manually giving these files executable permissions fixes the problem, but that is laborious, particularly when pip installed several dependencies that I need to chase up.
Is this a known issue? What can I do about it? For the record this is a RHEL6.4 machine and I'm using pip 1.4.1.
You best bet is virtualenv Do your workaround to install the virtualenv.
sudo pip install virtualenv
Resources for virtualenv to get you started:
http://simononsoftware.com/virtualenv-tutorial/
http://www.virtualenv.org/en/latest/

Categories

Resources