I am having trouble importing modules into my python projects. I just switched over to a 2020 Macbook Pro and think that this may have something to do with the problem since I never had problems before. This mac runs zhs as the default shell.
#!/usr/bin/python3
import time
import os
import selenium
This is the only code that I have written so far (I never used to need to specify that it was a python file with #!/usr/bin
...)
I get this error message: ModuleNotFoundError: No module named 'selenium'
and I am pretty sure that it isn't a problem with selenium since the same problem occurred when I tried to import yaml
When I enter a python shell through the terminal, I can import selenium with no error...
$ python3
Python 3.8.5 (default, Jul 21 2020, 10:48:26)
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import selenium
>>>
Both selenium and my new project are inside /usr/local/lib/python3.8/site-packages
I also tried modifying the PYTHONPATH
in zshrc
which didn't seem to help.
I think it should be a quick fix, but I'm not used to how this shell works. Any help greatly appreciated!
If you have pip installed you can install selenium like
pip install selenium
for python3 and based on your permissions you can try
sudo pip3 install selenium
Edit
Since you can import selenium with no error on the terminal, your IDE may be pointing to a different installation of Python than where Selenium is installed.
Check where the IDE is pointing and if it's not pointing to where
`python3 -c "import sys; print(sys.path)"`
this is pointing, correct it to that path and you're good to go.
If you're using an ide then while creating a project you should choose a virtual environment where you had installed that selenium
First you must check in which environment you had installed selenium.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.