1

I keep hitting this problem where the pulumi CLI tool runs, but whenever I try to do anything with it like pulumi up or pulumi preview it gives me this error that it can't find its own library:

    Traceback (most recent call last):
      File "/home/ubuntu/.pulumi/bin/pulumi-language-python-exec", line 16, in <module>
        import pulumi
    ModuleNotFoundError: No module named 'pulumi'

The last time I solved this I realized the root cause was that I'm using conda to manage my python environments. The tool suggests pip install pulumi which doesn't really work because then it'll just complain about No module named 'pulumi_aws' etc.

I've forgotten how I got around the problem, so I'm putting the question up here so when I figure it out I'll have a good place to post the solution. Or maybe somebody has knows the answer.

Leopd
  • 41,333
  • 31
  • 129
  • 167

1 Answers1

1

There's probably more than one way to skin this cat, but here's a way that works for me to fix this. It's to make sure you're using a pulumi-specific venv for the pulumi code.

In your project's Pulumi.yaml make sure the runtime is explicitly configured to use a venv:

runtime:
  name: python
  options:
    virtualenv: venv

Then running pulumi preview will instantiate the venv directory with at least some of the stuff you need. Likely not all of it though. You might still get ModuleNotFoundError, but now you can fix them by running commands like:

venv/bin/pip install pulumi
venv/bin/pip install pulumi_aws
# etc

At this point, the pulumi CLI will use the venv, and be able to find the libraries it needs.

Leopd
  • 41,333
  • 31
  • 129
  • 167