简体   繁体   中英

Create environment from existing folder/app with pip / conda

While developing my app I didn't use an environment. Now I want to use one and export all dependencies of my app in an environment.yml / requirements.txt file that afterwards I can use it to build a docker image.

The issue is, if I create an environment and then export it with:

conda env export > environment.yml

I get no dependencies in that file. Or if I use:

pip freeze --local > requirements.txt

I see all system modules that have nothing to do with my project.

I would imagine conda or pip has something that would just go through all my files in the directory I am and place all imports and their dependencies inside the environment.yml/requirements.txt file.

I can't find the command to do that..

You can use virtualenv to isolate your pip environment of your application from rest of your system. Use:

virtualenv <your_project_path>/venv

This will create a virtual environment of your app. Then use;

source venv/bin/activate

This will isolate your pip environment. Reinstall all your dependencies and run pip freeze you will see only project related dependencies.

pip freeze by default fetches all installed pip modules over the system. If you use virtualenv and then install your dependencies, your pip modules will reside in your application folder.

edit I would recommend a good IDE based on your comments such as PyCharm. You can follow tutorial here for setting up venv and handling all your dependencies. Once done, you can run pip freeze for your 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