Gracie williams
Gracie williams

Reputation: 1145

Importing module from virtual environment

I am completely new to python.I was able to install python in my macos and able to print hello world.I want to test out one 3rd party library and followed instructions from their documentation like below.

pip install virtualenv

virtualenv -p python3 breeze_venv

source breeze_venv/bin/activate

pip install --upgrade breeze-connect

I installed above things and my folder structure looks like below

enter image description here

Now in index.py , when i try to import the module like below

from breeze_connect import BreezeConnect
breeze = BreezeConnect(api_key="123")

I get following error

ModuleNotFoundError: No module named 'breeze_connect'

sorry if my question is newbie , today is my first day of python.

Upvotes: 1

Views: 266

Answers (2)

hamzeh_pm
hamzeh_pm

Reputation: 317

i try to explain the how the thing go then we can resolve the issue here when you install python on your system you have local python installed some where in your system that work with this command on your terminal

python the_path_to_file_to_run.py

when you install virtual environment as you do you install python on the folder you specified with this command virtualenv -p python3 breeze_venv in your case breeze_venv folder the you activate the virtual env with source breeze_venv/bin/activate when virtual env is activated as long as you are in there you don't work with you local version of python you work with your venv version you can see if your virtual env is activated by this

(name_of_you_virtual_env) mac-username

if it is not activated you terminal command prompt is like normal

mac-usrename

if you can verify that your are in virtual environment then you can run application with python path_to_your_script.py

if you want to use vs code to run you python make sure in bottom right of the vs code change the python interpreter to use your virtual environment

https://code.visualstudio.com/docs/python/environments

Upvotes: 0

YoshiMbele
YoshiMbele

Reputation: 999

Your index.py file (and all your other source code for that matter) is supposed to be next to the venv folder.

breeze
|- breeze_venv/
    |- bin/
    |- lib/
|- index.py

You can also check if PyCharm / VSCode / ... picked up on the venv you created earlier.

Upvotes: 1

Related Questions