Hi. I’m new to pulumi and I’m trying to get the py...
# python
s
Hi. I’m new to pulumi and I’m trying to get the python aws quickstart (https://www.pulumi.com/docs/get-started/aws/) example working using the github actions docs (https://www.pulumi.com/docs/guides/continuous-delivery/github-actions/) but I’m getting an error
error: "/github/workspace/venv" doesn't appear to be a virtual environment
. Can anyone here tell me how to activate my venv in the
uses:
block please? Thanks!
m
Hi Adrian, As of the most recent version of Pulumi (v2.4.0), when you create a new Pulumi Python program with
pulumi new
,
pulumi
creates a lightweight virtual environment in a
venv
directory, runs
venv\bin\pip install -r requirements.txt
to install dependencies in the virtual environment, and sets the
virtualenv: venv
option in
Pulumi.yaml
which tells the CLI to use that virtual environment when subsequent commands (like
pulumi up
) are run. In prior versions, you’d have to do this manually and ensure you’d run
pulumi up
from an activated shell. By default, a
.gitignore
file is generated for the project with an entry that excludes the
venv/
dir from Git, so by default the
venv
dir won’t be included in any commits. I’m guessing you’re seeing the error because you have
virtualenv: venv
set in
Pulumi.yaml
but no actual
venv
directory in the repo? We should consider improving the Pulumi GitHub Action to take the new
virtualenv
option in
Pulumi.yaml
into account, creating the virtual environment (if it doesn’t exist) and installing dependencies into it automatically. I’ve opened https://github.com/pulumi/pulumi/issues/4871 to track this. In the meantime, it’d probably be easiest to simply remove the
virtualenv: venv
option from
Pulumi.yaml
. This does mean when developing the program locally on your machine you’ll need to manage a virtual environment yourself (if you don’t want to be installing dependencies globally on your machine). On macOS/Linux you can do this via:
python3 -m venv venv
, activate it by using
source venv/bin/activate
, and then install dependencies into it via
pip install -r requirements.txt
. Be sure to run
pulumi preview
or
pulumi up
from the activated shell. Or use a tool like Pipenv to create/manage the virtual environment.