pip freeze does not show all installed packages - python

I am using a virtualenv. I have fabric installed, with pip. But a pip freeze does not give any hint about that. The package is there, in my virtualenv, but pip is silent about it. Why could that be? Any way to debug this?

I just tried this myself:
create a virtualenv in to the "env" directory:
$virtualenv2.7 --distribute env
New python executable in env/bin/python
Installing distribute....done.
Installing pip................done.
next, activate the virtual environment:
$source env/bin/activate
the prompt changed. now install fabric:
(env)$pip install fabric
Downloading/unpacking fabric
Downloading Fabric-1.6.1.tar.gz (216Kb): 216Kb downloaded
Running setup.py egg_info for package fabric
...
Successfully installed fabric paramiko pycrypto
Cleaning up...
And pip freeze shows the correct result:
(env)$pip freeze
Fabric==1.6.1
distribute==0.6.27
paramiko==1.10.1
pycrypto==2.6
wsgiref==0.1.2
Maybe you forgot to activate the virtual environment? On a *nix console type which pip to find out.

You can try using the --all flag, like this:
pip freeze --all > requirements.txt

Although your problem was specifically due to a typo, to help other users:
pip freeze doesn't show the dependencies that pip depends on. If you want to obtain all packages you can use pip freeze --all or pip list.

If you have redirected all the pre-installed packages in a file named pip-requirements.txt then it is pretty simple to fix the above issue.
1) Delete your virtualenv folder or create new one (I am giving it a name as venv)
rm -rf venv && virtualenv venv
2) Install all the requirements/dependencies from the pip-requirements.txt
pip install -r pip-requirements.txt
3) Now you can check the installed packages for your Django application
pip freeze
4) If you had forgotten to update your requirements file(pip-requirements.txt), then install fabric again (Optional Step)
Note: After installing any dependency for your Django app, always update the requirements in any file as follows (make sure your virtualenv is activated)
pip freeze > pip requirements.txt
That's it.

Adding my fix in addition of above fix also ,
I was also facing the same issue on windows,even after activating the virtualenv too pip freeze was not giving me all list of installed packages. So i upgraded my pip with python -m pip install --upgrade pip command and then used pip freeze.
This time it worked and gave me all list of installed packages.

This might be stupid but I have got the same problem. I solved it by refreshing vs code file directory (inside vscode there is a reload button). :)

If none of the above answers are working for you.
As with me you might have problem in you venv and pip configuration.
Go inside your venv/bin and open pip and see the 2nd line as:
'''exec' "path/to/yourvenv/bin/python3" "$0" "$#"
See if this line is correctly pointing inside your venv or not
For example in my case.
I initially named my virtual environment as venv1
and later just renamed it to venv2.
In doing so my pip file 2nd line had: '''exec' "venv1/bin/python3" "$0" "$#"
which to work properly should have: '''exec' "venv2/bin/python3" "$0" "$#" notice "venv2" not "venv1" since venv1 in now renamed to venv2.
Due to this python was looking inside pip of venv2 and throwing error or not working as desired.

For those who added Python modules via PyCharm IDE, after generating a virtual environment from the command prompt, good luck! You will need to rebuild the requirements.txt file manually with the ones missing by first running pip3 freeze and adding what is missing from PyCharm.
I highly suggest switching to Visual Studio Code.

Related

Installing requirements via "python -m pip install" randomly throws WinError5 exception

OS: Windows 10, 64-bit
Python: 3.9.1
Pip: 21.0.1
Editor: JetBrains Pycharm 2020.3.3
I have cloned a private GitHub repository via Pycharm and created the project's venv as usual after selecting my project interpreter. Ran python -m pip install -U --force-reinstall pip setuptools wheel after. Versions of all modules are up-to-date.
Pycharm automatically activates the created venv, so there is no need to manually activate it.
When running python -m pip install -r requirements.txt, this error (seemingly) randomly occurs:
ERROR: Could not install packages due to an OSError: [WinError 5] Access is denied: {file_path within venv}
Consider using the `--user` option or check the permissions.
I have checked for this error, and all sources seem to imply a permission mismatch, but I cannot figure out why there would be any.
So, I opened cmd as admin, navigated to my project folder and activated the venv through .\venv\Scripts\activate. There was no issue here.
Naturally, I ran python -m pip install -U --force-reinstall -r requirements.txt and the same error still occurred - even with admin permissions. (pip seems to fail randomly - sometimes e.g. numpy is able to be installed, sometimes not)
What could I try next in order to make it work? Have I made any mistakes so far? How could I proceed?
EDIT:
Using the --user flag does not work. ERROR: Can not perform a '--user' install. User site-packages are not visible in this virtualenv.
EDIT 2:
Deleting the venv directory, and reinstalling it with the following commands seems to have fixed the issue when installing the project requirements for the first time:
python -m venv .\venv
.\venv\Scripts\activate
python -m pip install -U --force-reinstall pip setuptools wheel
python -m pip install -r requirements.txt
The project is able to be run now, but out of curiosity, I tried running this command again:
python -m pip install -U --force-reinstall -r requirements.txt
The error still occurs, so it doesn't seem like the issue is fixed by recreating the venv, but at least the project can be run now. Not closing the question myself, as the "actual problem" does not seem to be fixed.
You probably have the problem, that sometimes code doesn't work due to a very long path.
Try to reinstall python(/the venv python) and search for a point where you can check a box so that the path isn't limited anymore

bash: virtualenv: command not found "ON Linux"

I am using a form of Lubuntu called GalliumOS (optimized for Chromebooks). I installed pip using $ sudo apt-get install python-pip. I then used pip install --user virtualenv and pip install virtualenv, and then when I tried to subsequently use virtualenv venv I experienced the message bash: virtualenv: command not found.
Between the pip installs above, I used pip uninstall virtualenv to get back to square one. The error remained after a reinstall.
I read several other posts, but all of them seemed to deal with similar problems on MacOS. One that came close was installing python pip and virtualenv simultaneously. Since I had already installed pip, I didn't think that these quite applied to my issue. Why is pip install virtualenv not working this way on LUbuntu / GalliumOS?
Are you sure pip install is "failing"? To me, it sounds like the directory to which pip is installing modules on your machine is not in your PATH environment variable, so when virtualenv is installed, your computer has no idea where to find it when you just type in virtualenv.
Find where pip is installing things on your computer, and then check if the directory where the pyenv executable is placed is in your PATH variable (e.g. by doing echo $PATH to print your PATH variable). If it's not, you need to update your PATH variable by adding the following to your .bashrc or .bash_profile or etc.:
export PATH="PATH_TO_WHERE_PIP_PUTS_EXECUTABLES:$PATH"
What finally worked for me was this. I used
$ sudo apt-get install python-virtualenv.
I was then able to create a virtual environment using $ virtualenv venv.
I was seeking to avoid using $ sudo pip install virtualenv, because of admonitions in other posts to not do this, and agreed, because of experiences I'd had with subsequent difficulties when doing this.
pip install virtualenv
This command worked for me for. This problem that raised to me on Kali Linux.

how to install setuptools in mac

I'm trying to install via pip some libraries but I'm having some problems.
When I try to install some of them I require for my project I get this message:
$ sudo pip install dj-database-url==0.2.0
Downloading/unpacking dj-database-url==0.2.0
Downloading dj-database-url-0.2.0.tar.gz
Cleaning up...
setuptools must be installed to install from a source distribution
It also happens when trying to install distribute==0.6.24
Any ideas?
Download ez_setup.py module from https://pypi.python.org/pypi/setuptools
Open a Terminal.
cd to the directory where you put the ez_setup.py.
Type python ez_setup.py and run it.
You should have it then.
After a pip install command I was getting the same error as you ("setuptools must be installed to install from a source distribution"). Since I couldn't find a solution, it was a lot faster to reinstall the virtual environment where python was running from.
If you're using virtualenvwrapper this is very easy. First you remove your problematic virtual environment (let's say it is called "venv") with:
rmvirtualenv venv
Then you setup a new one with the same name:
mkvirtualenv venv
And finally you install all your packages, including the one you had problems with:
pip install dj-database-url

Error With Installing Virtualenv With Pip and Homebrew

I am trying to get a nice clean Python environment setup on OSX 10.9. I've installed Python with Homebrew and set my PATH variables so...
> which python
/usr/local/bin/python
and
> which pip
/usr/local/bin/pip
so when I look at my /usr/local/bin :
pip -> ../Cellar/python/2.7.6/bin/pip
python -> ../Cellar/python/2.7.6/bin/python
then when I run:
> pip install virtualenv
I get permission errors on /usr/local/bin/virtualenv:
...
running install_scripts
Installing virtualenv script to /usr/local/bin
error: /usr/local/bin/virtualenv: Permission denied
I thought that by using Homebrew I could use pip and avoid using sudo to install virtualenv. Am I doing something wrong here?
Ok! I managed to fix this myself.
I deleted all the virtualenv related things from /usr/local/bin (they had been installed under root for some reason and this was causing my permission issues.).
Then I did a pip uninstall virtualenv to get rid of other instances of virtualenv, as there was still one in /usr/local/lib/python2.7/site-packages/
Then a simple pip install virtualenv and things work fine now!
Most likely HomeBrew does some magic so that running brew install allows writing to /usr/local/bin, but this privilege is not available to normal commands. This is a guess, I didn't investigate this further.
Install virtualenv with brew:
brew install pyenv-virtualenv
This command:
pip install virtualenv
runs pip from your first directory from $PATH environment variable, which is usually system wide, thus when you run in this way - you are trying to install it globall.
You should install you your environment in your $HOME directory:
virtualenv $HOME/myvirpython
and later:
$HOME/myvirpython/bin pip install something
Additionally you should read this:
https://docs.brew.sh/Homebrew-and-Python

Why would pip install python packages outside of my current virtualenv?

I just installed virtualenv earlier today, and I've been trying to get django-nonrel to work using a virtual environment. After many hours of trying and failing to do so, I chatted with someone who suggested that the problem is with pip itself.
I create a virtual environment with virtualenv env_name. I enter it with:
source env_name/bin/activate
I then install something with pip. For example,
sudo pip install git+https://github.com/django-nonrel/django-nonrel;
I then perform a pip freeze, and the only output is:
wsgiref=0.1.2
Can anyone see why this might happen?
Thanks,
ParagonRG
Notes:
pip is version 1.1.
virtualenv is version 1..7.1.2
You forgot the git extension
$> mkvirtualenv test
(test)> pip install git+https://github.com/django-nonrel/django-nonrel.git
(test)> pip freeze
Django==1.3.1
wsgiref==0.1.2
By the way, you dont need to use sudo if you work with virtualenv. The idea is having your virtualen somewhere you have permission like ~/.virtualenvs/

Categories

Resources