Home > other >  Importing a module in a script
Importing a module in a script

Time:12-21

So, I have been working in the jupyter lab and I have created a code that uses numpy.

In the jupyter I had no problem using numpy. I installed the library, and I used the command import to use such module.

However, I had to save my code as a py file. When I try to run my py file using my cmd, I receive this message:

ModuleNotFoundError: No module named 'numpy'

If i type in my cmd "pip show numpy" it shows me that I have numpy installed.

I also have tried to add to my code a line with:

pip install numpy

pip3 install numpy

python -m pip install numpy

python3 -m pip install numpy

conda install -c anaconda numpy

conda install numpy

and for every option I received a syntax error:

SyntaxError: invalid syntax

Can someone help me?

CodePudding user response:

As mentioned in the comments section, it seems like your Python script (.py) was not using the correct environment. Please ensure that correct virtual environment is selected by doing conda activate name_of_the_kernel, where name_of_the_kernel should match the kernel used in your Jupyter notebook.

  • Related