0

Normally when I want to run a script from the command prompt or shell I navigate to the directory my script file is in and type python <name script>.py and press Enter

D:\TestPython>python run.py
here a demo run

However at the moment a script I want to run relies an a package in the virtual environment. In the Python documentation I found a way to solve this relying on the execution of an activate.bat file:

D:\TestPython>C:\Users\elmex\VENV\Scripts\activate.bat 
(VENV) D:\TestPython>python run.py
here a demo run

Now I wonder if there is an alternative to this, something like D:\TestPython>python use all packages form virt env this <dir> run.py.

2
  • 1
    For your first example, if your system is configured properly you can add D:\TestPython to the PATH environment variable and .PY to the PATHEXT environment variable. Then you can execute run from any working directory. The shell will find "run.py", get the associated command template (e.g. py.exe "%1" %*), expand the template, and execute the command. Commented Mar 9, 2017 at 20:58
  • 1
    For running a script in a virtual environment, install Python 3 to get the py.exe launcher as the default association for .py files. Then in run.py add a shebang with the fully-qualified path to that interpreter, e.g. #!C:\Users\elmex\VENV\Scripts\python.exe. Commented Mar 9, 2017 at 21:01

1 Answer 1

1

so sorry @Elmex80s there are no way for that in the other way yes I meant from inside a virtualenv you can access to the packages installed in you global system but before install this virtual env you need to use the option system-site-packages and you would have the access I talking about it. You can see all this here:https://virtualenv.pypa.io/en/stable/reference/#cmdoption--system-site-packages Regards

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.