Python and virtualenv - how do I run my app?

Discussion in 'Programmer's Corner' started by mbxs3, Sep 11, 2016.

  1. mbxs3

    Thread Starter Senior Member

    Oct 14, 2009
    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
    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 I have to be in this virtual environment, instead of just being able to execute 'python' 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 file from a batch file dictated by the TaskScheduler.
  2. upand_at_them

    Senior Member

    May 15, 2010
    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.
  3. mbxs3

    Thread Starter Senior Member

    Oct 14, 2009
    I ended up going that route... Installing the two packages globally.