Ferazhu
Ferazhu

Reputation: 99

Launching python virtualenv code outside of Visual Studio

I have a Python code in Visual Studio which reads input, opens a file based on it, then makes a pyplot based on the file and saves the plot. All files are in the same folder as the .sln file.

To use the matplotlib package, I have used virtual environment. That led to creating "env" folder, but I can not find my application there.

So I would like to know a way how can I launch the code via doubleclicking a .py application, instead of launching Visual Studio and pressing Ctrl+F5 every time. Simply copying the code into "mycode.py" obviously doesn't work.

Upvotes: 1

Views: 420

Answers (1)

Aykut Yilmaz
Aykut Yilmaz

Reputation: 331

You need to activate the virtualenv in order to execute your Python code inside your virtual environment.

To activate the virtual environment you have to type the following in the terminal:

On macOS and Linux:

source env/bin/activate

On Windows:

.\env\Scripts\activate

You can confirm you’re in the virtual environment by checking the location of your Python interpreter, it should point to the env directory.

On macOS and Linux:

which python
.../env/bin/python

On Windows:

where python
.../env/bin/python.exe

To execute your python file just type python myfile.py in the terminal instead of double-clicking it.

Upvotes: 1

Related Questions