How to make sure python script uses virtual environment?

前端 未结 2 797
执念已碎
执念已碎 2021-01-23 01:20

I created virtual environment and activate it. installed packages but unable to import them from virtual environment.

pip freeze:

But

2条回答
  •  北海茫月
    2021-01-23 01:34

    You should invoke the python that is installed within your environment. That is

    source myenv/bin/activate
    python path/to/script.py
    

    In Unix, you would add the following #!/usr/bin/env python at the top of your script and this would allow you to run it without specifying the python binary.

    source myenv/bin/activate
    path/to/script.py
    

    Possibly that works in Windows in the same way or differently.

提交回复
热议问题