David 54321
David 54321

Reputation: 728

pip freeze showing all libraries, not the ones in my virtual env

Pip Freeze shows all the libraries I have on my computer not just the libraries in the virtual environment.

I am trying to create a requirements.txt file for my virtual environment. I'm using an anaconda distribution. I am creating a flask app. I have navigated to my project folder created the virtual environment added flask and then when I make the command pip freeze it clearly shows items that are not in my virtual environment like xlwings, pandas and stuff I use that has nothing to do with flask.

Any way I can create a requirements file from my virtual environment.

I can clearly see my virtual environment is active with (venv) to the left.

Edit: I created a short video showing I get the same list of libraries whether I'm in my virtual environment or not. Also I'm showing the site-packages in my virtual environment and showing that these libraries aren't there I'm specifically pointing out xlwings.

https://youtu.be/xEFZ3dSaqoY

Upvotes: 5

Views: 5690

Answers (5)

Farshid Ahmadi
Farshid Ahmadi

Reputation: 513

I had same problem when tried rename directory which was set for virtualenv. The only solution for me was making another virtual environment again and moving everything in it.

Upvotes: 0

Pradeep Maurya
Pradeep Maurya

Reputation: 1

In my case i was using vscode IDE so when i created .venv its recommended use worksapce, so i choosed yes thats why its took all from my system' lib.

for this you can delete old on .venv and create new one, this time don't choose plugin's recommendations.

for create veirtual enviroment in window/linx python -m venv .venv or python3 -m venv .venv

to activate .venv win use (.venv\scripts\activate) and for linux use (source .venv/bin/activate)

all command like pip freeze, pip list, pip freeze > requirements.txt will work

Upvotes: 0

Sebastian Rojas
Sebastian Rojas

Reputation: 29

I had this same problem and it happened because i change the name of my venv folder. To solve this i used this command in my terminal [yourVenv]\Scripts\python -m pip freeze.

If you don't want to do it like this everytime, try creating a new enviorment like this.

[yourVenv]\Scripts\python -m pip freeze > requirements.txt
python -m venv [yourVenv]
[yourVenv]\Scripts\activate
python -m pip install --upgrade pip
pip install -r requirements.txt

Upvotes: 1

David 54321
David 54321

Reputation: 728

So i'm not sure why it was happening, but I deleted the virtual environment and re-created it (I had a previous requirements.txt that was correct). Then I ran pip freeze again and it all worked. Not sure what happened, but it works for me now.

Upvotes: 2

You need to activate your pip environment in the console that you are trying to run pip freeze in. That way it uses the environment's pip and not your global pip.

So in your console, navigate to your virtual environment folder. From there go to the "Scripts" folder. Then enter the word "activate" into the console.

You should then see next to the console cursor the name of your virtual environment. At that point you can use the pip that's inside of your virtual environment and all the normal pip commands will point to it.

Upvotes: 0

Related Questions