Does anyone know how to run python script with python from virtual environment without cmd. In Linux it is easy with shebang.
Problem is that I have installed Python2 and on MyProject I have created virtual environment in Python3. Now when I click on main.py in MyProject I get syntax error and that is normal because it calls Python2 and in main.py I use async def that in Python2 doesn't exist.
What I must add in main.py so that it automatically recognises that it should be executed by python3 located in virtual environment and not with windows assigned default python2.
I don't want to use cmd and I want all in main.py that is needed to run that py on click.
Any ideas?
Check the link: Detect Python version at runtime
You can add the following lines in your code.
import sys
if sys.version_info[0] < 3:
raise "Must be using Python 3"
else:
from your_script import your_method
your_method()
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.