Activate venv from within Python3 Script

We want to deliver a ready-to-deploy venv for different versions of our software.

Therefore, I wanted to write a simple Python script, which calls a couple of bash commands for installing every package we need.

So the steps are:

  1. Create a venv with a Name suffixed with version number
  2. Activate this venv
  3. Install packages from PyPy
  4. cd into a couple of local packages folders
  5. Install them by git install .
  6. cp a couple of files in the venv folder

My problem now is, I can't find a way to activate the venv from within the script. I already read about how it was done in Python 2 (with execfile) and about the exec(open(path_to_env_activate).read()) in Python 3.

However, the second version for Python3 gives me a Syntax Error:

Traceback (most recent call last):
  File "build.py", line 32, in <module>
    exec(open(venv_activate).read())
  File "<string>", line 1
    @echo off
            ^
SyntaxError: invalid syntax

What did I get wrong here? Or is there kinda best practice how to install venv with packages with a script?



Read more here: https://stackoverflow.com/questions/45161759/activate-venv-from-within-python3-script

Content Attribution

This content was originally published by Igle at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: