Automatically create requirements.txt

前端 未结 7 1656
灰色年华
灰色年华 2020-11-27 09:07

Sometimes I download the python source code from github and don\'t know how to install all the dependencies. If there is no requirements.txt file I

相关标签:
7条回答
  • 2020-11-27 09:42

    Make sure to run pip3 for python3.7.

    pip3 freeze >> yourfile.txt
    

    Before executing the above command make sure you have created a virtual environment.

    python3:

    pip3 install virtualenv
    python3 -m venv <myenvname> 
    

    python2:

    pip install virtualenv
    virtualenv <myenvname>
    

    After that put your source code in the directory. If you run the python file now, probably It won't launch If you are using non-native modules. You can install those modules runing

    pip3 install <module> or pip install <module> 
    

    This will not affect you entire module list except the environment you are In.

    Now you can execute the command at the top and now you have a requirements file which contains only the modules you installed in the virtual environment. Now you can run the command at the top.

    I advise everyone to use environments as It makes things easier when It comes to stuff like this.

    Hope this helped.

    0 讨论(0)
提交回复
热议问题