Solution for How to run a virtual environment python file from the outside?
is Given Below:
I have a virtual environment python file and i want to run it from the outside (by double clicking in the python file)
but it doesn’t run. it only works when I run it in VS code.
what should I do?
I wish someone can help
Python version: 3.8.10
From what I tell, you have certain dependencies that your script requires that you have only installed inside of the venv, it will only run when it finds those packages otherwise it will throw an error and exit, that is why when you click on your python file it exits immediately. Eg:
I have a venv called ‘web’ where I make web applications, if I go to cmd and type:
C:website> python main.py Traceback (most recent call last): File "C:main.py", line 1, in <module> import flask ModuleNotFoundError: No module named 'flask'
Now, if I type:
C:website> workon web (web) C:website> python main.py Running at http://127.0.0.1:5000/
See, you have to activate your virtual env first to make it work, follow all these steps and it should run.
If you want to send this project/script as a standalone package, you might want to use docker.