getting an error in VS - help please
Hi,
I am getting an error code when i write the code import numpy as np and import cv2.
/usr/local/bin/python3 /Users/elisha/capstone_solution.py
(base) elisha@elishas-Mini ~ % /usr/local/bin/python3 /Users/elisha/capstone_solution.py
Traceback (most recent call last):
File "/Users/elisha/capstone_solution.py", line 1, in <module>
import numpy as np
ModuleNotFoundError: No module named 'numpy'
Please help.
Cheers
Hey Elisha,
Thank you for reaching out!
Please, make sure that the numpy
library is installed in the environment you are using.
Kind regards,
365 Hristina
Hi Hristina,
I installed numpy using pip install numpy in my terminal, however, perhaps I am installing it in the wrong environment. How do I make sure I am in the right environment when I install numpy on the terminal? For each environment, is there a separate terminal?
Cheers
Elisha
Hey again Elisha,
In the screenshot below, I have outlined the steps you would need to perform:
Notice the parentheses in front. If they say base
, then you are in the base
environment. To see all available environments, type
conda env list
and hit Enter. The star indicates the environment you are currently in. Going through the list, I can see that there is an existing environment called capstone
. To enter the environment, type
conda activate capstone
Notice how the text inside the parentheses has now changed. Next, using the command
pip list
you will see all packages installed through pip
. If numpy
is not on the list, you can install it by typing
pip install numpy
What I can suggest is this very useful cheat sheet that the Anaconda team have created. I always refer to it when working with the conda prompt.
Hope this helps! Let me know if the problem persists :)
Kind regards,
365 Hristina
Hi Hristina,
Thank you for the very helpful response. I now understand how to navigate through the different environments I have in anaconda. However, my system says the following when I do exactly as what you did:
It says command not found: pip
Please could you help me resolve this? Thank you so much.
Hey Elisha,
It seems like pip
is not installed in the capstone
environment. Try to list the packages using conda
, namely:
conda list
and then install the missing packages (for example, numpy
) using the command
conda install numpy
Let me know if this works!
Kind regards,
365 Hristina
Hi Hristina,
It seems that worked, and installed numpy and pip in my capstone env at the same time. Can I ask if this is the way to install pip in any environment? I just have to write conda install numpy? Is numpy related to pip? I ask because Pip seems to be useful in installing other modules as well for different environments and I'd like to learn how to get pip each time.
Cheers
Hi Hristina,
Sorry to bother you again, I ran into another problem with installation of Open CV. I tried the method you mentioned,and I think it worked because based on the terminal I can see this:
I can see that numpy was part of the ones which was installed in my new environment. In my case I called it 'capstone2.'
However, after that, when I try to follow Giles' video to launch VS code, and then type in import numpy as np and import cv2, I get an error saying:
(capstone2) elisha@elishas-Mini ~ % /Users/elisha/opt/anaconda3/envs/capstone2/bin/python /Users/elisha/capstone2_solution
.py
Traceback (most recent call last):
File "/Users/elisha/capstone2_solution.py", line 2, in <module>
import cv2
ModuleNotFoundError: No module named 'cv2'
Please can you help me resolve this?
Cheers
Elisha
Hey Elisha,
Thank you for your reply!
Let me suggest the following article by the Anaconda team which describes the similarities and differences between the two tools. Hope you find it useful! :)
Kind regards,
365 Hristina
Hey again Elisha,
Regarding the last question you have, you would need to install opencv
in the following way:
conda install -c conda-forge opencv
Of course, you need to do this inside the capstone2
environment.
Let me know if this helps :)
Kind regards,
365 Hristina
Hi Hristina,
Thank you for your quick reply.
I did as you told me, I reopened the terminal and typed conda install -c conda-forge opencv in the capstone2 environment which I created. It seems to have run, as you can see from my screenshots of my terminal:
After that was finished I went back to conda to launch VScode, and continued on by running import numpy as np and import cv. I still get the same error though:
It still syas no module named cv2.
Would you know why this is happening please? Could you please help me ? Thank you so much for your help.
Hey Elisha,
Thank you for the screenshots, they helped me a lot!
In the bottom right corner of Visual Studio, you can see that you are in the base environment
If you are launching Visual Studio from the Anaconda Navigator, you would first need to change the environment by choosing
Applications on -> capstone2
Then, launch Visual Studio and the bottom right corner should now read 'capstone2'.
Hope this helps! Let me know how it went! :)
Kind regards,
365 Hristina