Forums

Importing module from virtualenv?

Sorry if this sounds super novice, I'm new to registering apps and find the process very confusing.

I am trying to access a module installed in my virtualenv in my python script. Per the directions, it says you have to register it as a web app to access it. But my file is just a simple bot script, and it wouldn't make sense for me to register it as a web app. So how can I access the module in my file from the virtualenv without registering it as a web app??

If you want to use a virtualenv for a script, just activate it in the Bash console before you run your code with:

workon myvirtualenvname

or whatever you've called your virtualenv.

I tried that but its still giving me a ModuleNotFoundError. I also tried pip install lyricsgenius while in my virtualenv again and it says requirements already satisfied.

Where are you seeing the ModuleNotFoundError? Is it in response to a command that you are typing into a console? Or is it appearing somewhere else?

Its appearing in the console after I try to run the script

Oh do I have to run it via the console direclty with terminal command while in my virtualenv? Rather than hitting the "run" button?

You need to make sure that you are running it within your virtualenv. This could mean using the terminal, activating your virtualenv, or if you are using the run button, you should specify which python to use in this way.

ok thanks!