Python and virtualenv - how do I run my app?

Thread Starter

mbxs3

Joined Oct 14, 2009
170
Preface: I started looking at Python two days ago so not a lot of experience. However, all the tutorials I came across emphasized the usage of virtualenv, so of course I went along.

Fast forward to now and I have a Python .py that does what I want it to do -- lets call it test.py
1)Makes a connection to a remote SQL server (had to use pyodbc)
2)I execute some queries and utilize the data the way I want to
3)I send some results out to a serial port (had to use pyserial)

pyodbc and pyserial were installed with pip in the virtualenv.

Now, to run test.py I have to be in this virtual environment, instead of just being able to execute 'python test.py' from anywhere on the command line.

In all the tutorials I came across, as well as other quick google searches of virtualenv usage, I never grasped how the .py was supposed to be utilized in conjunction with the virtualenv that contain these dependencies (pyodbc and pyserial).

(**Probably worth mentioning that I am working in a Windows environment**)

Ultimately, I want to launch my test.py file from a batch file dictated by the TaskScheduler.
 

upand_at_them

Joined May 15, 2010
940
You don't absolutely have to run a virtual environment. You can install the package requirements via pip outside of the virtual environment and run your Python script as normal. That's what I do. My work machine even has Python scripts scheduled to run at various times.

I can see the potential value in using a virtual environment. I just have never needed one.
 

Thread Starter

mbxs3

Joined Oct 14, 2009
170
You don't absolutely have to run a virtual environment. You can install the package requirements via pip outside of the virtual environment and run your Python script as normal. That's what I do. My work machine even has Python scripts scheduled to run at various times.

I can see the potential value in using a virtual environment. I just have never needed one.
I ended up going that route... Installing the two packages globally.
 
Top