Basically I am trying to run some simple code in sublime text 3 but when I try to run it it gives me the following error:
File "/Users/ingodavila/Desktop/My Programming/scrape.py", line 1, in <module>
from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'
I have tried installing it with pip3 and easy_install but it does not work. Whenever I try installing it it in terminal it keeps showing:
Requirement already satisfied: bs4 in ./opt/anaconda3/lib/python3.8/site-packages (0.0.1)
Requirement already satisfied: beautifulsoup4 in ./opt/anaconda3/lib/python3.8/site-packages (from bs4) (4.9.1)
Requirement already satisfied: soupsieve>1.2 in ./opt/anaconda3/lib/python3.8/site-packages (from beautifulsoup4->bs4)
I tried running it in a jupyter notebook and it works but for sublime it keeps showing that 'nomodulefound' error. What can I do to solve this?
Are you running the code inside a virtual environment?
If you are, try this method:
activate the env
install the module (inside the virtualenv)
run the code.
If the above doesn't work, try:
conda install bs4
It is probably because your Sublime text interpreter is different than your global one. I would recommend you using virtual environment instead of just installing modules globally. Check this one out on how to create venv. Once you set up your virtualenv and active it, you can just install packages and use them without any problem.
Related
So ive tried to install customtkinter and the installation was successfull
Using cached customtkinter-4.6.3-py3-none-any.whl (246 kB)
Requirement already satisfied: darkdetect in c:\users\omen1\appdata\local\programs\python\python311\lib\site-packages (from customtkinter) (0.7.1)
Installing collected packages: customtkinter
Successfully installed customtkinter-4.6.3
But when i then go to vs code and write import customtkinter and run it says
Traceback (most recent call last):
File "c:\Users\OMEN1\OneDrive\Skrivbord\python projects\database.py", line 290, in <module>
import customtkinter
ModuleNotFoundError: No module named 'customtkinter'
I have tried to uninstall and re-install
My pip is also fully uppdated aswell as my python 3.11
Ive tried multiple things
Ensure that the interpreter you're using in VSCode is aligned to where you installed the library.
For example if you installed it with Python3, your VSCode may be pointed to Python2 instead.
Additionally, according to the PyPi link for that library - "To use CustomTkinter, just place the /customtkinter folder from this repository next to your program, and then you can do import customtkinter."
Every time when i try to import the bs4 module i get this error
ModuleNotFoundError: No module named 'bs4'
When i try to install the bs4 module i get this message on the console:
C:\Users\gabri>pip install bs4
Requirement already satisfied: bs4 in c:\users\gabri\appdata\local\programs\python\python39\lib\site-packages (0.0.1)
Requirement already satisfied: beautifulsoup4 in c:\users\gabri\appdata\local\programs\python\python39\lib\site-packages (from bs4) (4.9.3)
Requirement already satisfied: soupsieve>1.2 in c:\users\gabri\appdata\local\programs\python\python39\lib\site-packages (from beautifulsoup4->bs4) (2.2.1)
When i try to import the requests module that's working i get this message:
C:\Users\gabri>pip install bs4
Requirement already satisfied: bs4 in c:\users\gabri\appdata\local\programs\python\python39\lib\site-packages (0.0.1)
Requirement already satisfied: beautifulsoup4 in c:\users\gabri\appdata\local\programs\python\python39\lib\site-packages (from bs4) (4.9.3)
Requirement already satisfied: soupsieve>1.2 in c:\users\gabri\appdata\local\programs\python\python39\lib\site-packages (from beautifulsoup4->bs4) (2.2.1)
My python version is:
Python 3.9.5
My pip version is:
pip 21.1.2 from c:\users\gabri\appdata\local\programs\python\python39\lib\site-packages\pip (python 3.9)
I used to have anaconda installed and then i installed python again. I read in some post that maybe the problem was happening because of two versions of python installed than i uninstall anaconda and jupyter. However nothing change. Some people said to me that my pip was install in another python besides the one i am trying to run, but i dont know how to change that. The code i'm trying to run in this
import requests as r
from bs4 import BeautifulSoup
try:
result = r.get('https://www.google.com.br/search?q=Python')
except Exception as err:
print("Something went wrong: ",err)
else:
response = result.text
soup = BeautifulSoup(response,'html.parser')
print(soup.title)
print(soup.title.string)
And the error is this:
>>> %Run teste.py
Traceback (most recent call last):
File "C:\Users\gabri\teste.py", line 2, in <module>
from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'
I think that my pip is install in this path:
pip 21.1.2 from c:\users\gabri\appdata\local\programs\python\python39\lib\site-packages\pip (python 3.9)
and my python is install in this path:
C:\Users\gabri\AppData\Local\Programs\Python\Python39\python39.zip
C:\Users\gabri\AppData\Local\Programs\Python\Python39\DLLs
C:\Users\gabri\AppData\Local\Programs\Python\Python39\lib
C:\Users\gabri\AppData\Local\Programs\Python\Python39
C:\Users\gabri\AppData\Local\Programs\Python\Python39\lib\site-packages
Thats a picture of my paths on windows
enter image description here
I try put the file with the code that i'm trying to run inside the path of bs4 and it worked. But i would like to know if there is an easy method besides that
So with the helping of #He3lixx i found the answer to the question. My IDE, Thonny was using the wrong sys path to import the bs4 module. The module that pip install bs4 was in the python installation folders. So i change the paths imports in the IDE settings. To figure out what paths the IDE was using and compare to the path the bs4 was installed i use this code in the IDE shell:
import sys
for sys in sys.path:
print (sys)
The logical answer, if I don't have a specific module is to just install it. pip install pyyaml but I have installed it, and this just spits back "Requirement already satisfied: pyyaml in /usr/lib/python3.8/site-packages (5.3.1)".
I got this issue while setting up Baxter for Gazebo.
PLUS INFO: I can import it for any other project, except this.
When I do:
import xgboost
I get no module named xgboost
I tried:
pip install xgboost
and i get:
Requirement already satisfied: xgboost in e:\anaconda\lib\site-packages (1.0.2)
Requirement already satisfied: numpy in e:\anaconda\lib\site-packages (from xgboost) (1.18.1)
Requirement already satisfied: scipy in e:\anaconda\lib\site-packages (from xgboost) (1.4.1)
versions
Python 3.7.4
pip 20.0.2 from E:\Anaconda\lib\site-packages\pip (python 3.7)
Where python:
E:\Anaconda\python.exe
C:\Users\Federico\AppData\Local\Microsoft\WindowsApps\python.exe
Usually this will happen because
You installed the package in a virtualenv and are trying to import it outside of the env
You installed the package globally and are trying to import it in a virtualenv which does not inherit the global packages
Your pip is linked to a different version than the python you're using
Based on the output of the where python it seems like you probably used the pip from anaconda to install the package, but are trying to import the package in a script that you're running with the python located here C:\Users\Federico\AppData\Local\Microsoft\WindowsApps\python.exe rather than here E:\Anaconda\python.exe
If your code with the import is in a script called test.py, for example, try running it with E:\Anaconda\python.exe test.py and see if the error still occurs
Or start a Python shell with E:\Anaconda\python.exe and then execute import xgboost in the shell and see if that works
I downloaded Python 3.7 and am running a script with "from bs4 import BeautifulSoup" and am receiving the following error on execution;
"File "myscript.py", line 3, in
from bs4 import BeautifulSoup ImportError: No module named bs4"
When I type "pip3 install bs4" or "pip3 install BeautifulSoup4" in the terminal I get the following;
"Requirement already satisfied: bs4 in
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages
(0.0.1) Requirement already satisfied: beautifulsoup4 in
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages
(from bs4) (4.6.3)"
Executing "import bs4" and "from bs4 import BeautifulSoup" in IDLE don't error out.
Any idea about what's going on?
Just pip install bs4.
Probably, you are maintaining different versions of Python.
check if you have more than one version of python, if so add the path of python 3.7 in the system setting and try removing the older python if possible
and then pip install BeautifulSoup
I had a similar problem with importing bs4. There is a similar question with many answers. I tried many things and nothing worked but when I installed poetry [https://python-poetry.org/ ]
$ poetry add pendulum
It sorted dependencies for me so I was able to import bs4.