简体   繁体   中英

pip freeze without Conda packages

I have been using Conda for a while and it has been very helpful. However, it has happened to me lately, that when I run the command

pip freeze > requirements.txt

to pass my project to another laptop, the requirements.txt file is full of Conda packages, such that when I try to restore them with the command

pip install -r requirements.txt

it cannot find them and fails.

My question is, is it possible to do a pip freeze where the pip command does not consider Conda packages ?

At the end of the day, I only use Conda to create separate Python workspaces.

The conda list command will indicate PyPI packages with a pypi in the Channel column. Hence, a quick way would be to filter on that, eg,

conda list | awk '$4 ~ /pypi/ { print $1 "==" $2 }'

It should be mentioned that a more idiomatic workflow for sharing environments is to use conda env export , which also captures (and separates) packages from PyPI. See the Conda documentation on sharing environments for details.

If you are pretty sure that Anaconda is not essential for this project, you can manually remove it's packages from requirements.txt.

Conda packages are often defined with an @.

Here is a code to remove them:

Linux:

pip freeze | grep -v "@" > requirements.txt

Windows

pip freeze | findstr /v "@" > requirements.txt

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