I've python script which uses the YAML. but it's giving an Import Error for YAML module as below:
ImportError: No module named yaml
I've also tried to install pyyaml, but it shows that it's already installed.
pip install pyyaml gives below output:
Requirement already satisfied: pyyaml in /usr/local/lib/python3.6/site-packages (5.1.1)
I've also checked in pip list, it also shows PyYAML with 5.1.1 version in list.
What should be done here to run this script?
Related
I am trying to import certain packages as I am working with Jupyter notebook files, and most of the packages seem to be missing, even though I have installed them. For example, when I do the command: from bs4 import BeautifulSoup or import requests
I get the error saying ModuleNotFoundError: No module named 'bs4' for the first one and a similar one for importing requests as well. I have tried pip install requests and pip install bs4, but same issue persists. I have installed them on:
"(base) aminnazemzadeh#amins-MacBook-Pro ~ % " which seems to be my home directory, and I also have anaconda3 installed alongside python3. What is the issue that I cannot import these modules.
I am using visual studio if it makes any difference
Once I add :
!pip install requests
!pip install bs4
I get:
/Users/aminnazemzadeh/.zshenv:.:1: no such file or directory: /Users/aminnazemzadeh/.cargo/env
Requirement already satisfied: requests in /Users/aminnazemzadeh/opt/anaconda3/lib/python3.9/site-packages (2.28.1)
Requirement already satisfied: charset-normalizer<3,>=2 in /Users/aminnazemzadeh/opt/anaconda3/lib/python3.9/site-packages (from requests) (2.0.4)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /Users/aminnazemzadeh/opt/anaconda3/lib/python3.9/site-packages (from requests) (1.26.11)
Requirement already satisfied: idna<4,>=2.5 in /Users/aminnazemzadeh/opt/anaconda3/lib/python3.9/site-packages (from requests) (3.3)
Requirement already satisfied: certifi>=2017.4.17 in /Users/aminnazemzadeh/opt/anaconda3/lib/python3.9/site-packages (from requests) (2022.9.24)
/Users/aminnazemzadeh/.zshenv:.:1: no such file or directory: /Users/aminnazemzadeh/.cargo/env
Requirement already satisfied: bs4 in /Users/aminnazemzadeh/opt/anaconda3/lib/python3.9/site-packages (0.0.1)
Requirement already satisfied: beautifulsoup4 in /Users/aminnazemzadeh/opt/anaconda3/lib/python3.9/site-packages (from bs4) (4.11.1)
Requirement already satisfied: soupsieve>1.2 in /Users/aminnazemzadeh/opt/anaconda3/lib/python3.9/site-packages (from beautifulsoup4->bs4) (2.3.1)
followed by this warning:
ModuleNotFoundError Traceback (most recent call last)
Cell In[7], line 4
2 get_ipython().system('pip install bs4')
3 from urllib.request import urlopen
----> 4 from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'
Thanks
probably you're installing the packages on an environment other than the one vs code is using. you can try installing the packages directly from your jupyter notebook by running the following code in a notebook cell. the current best practice to be running installs in the notebook is using the magic commands %pip or %conda:
%pip install requests beautifulsoup4
# or
%conda install requests beautifulsoup4
this should install the packages in the same environment that the notebook is running on.
note that you may need to restart the kernel to use the affected packages.
sources:
Jupyter Discourse Forum - Location of libraries or extensions installed in JupyterLab
Jupyter Discourse Forum - Why users can install modules from pip but not from conda?
Installing Beautiful Soup
ps: thanks #wayne for the comments regarding the current best practices for installing on the current running environment.
If you're using conda, you should install via conda whenever possible. When you install via pip, conda loses some of its ability to manage dependency versions.
Try creating a new conda environment, install the needed packages via conda, then set the kernel to your new environment in vscode. Dedicate conda environments to specific projects. It is okay to have a default/generic environment for playing around but not for any significant work as you can easily create errors in your other work if a dependency changes to an incompatible version.
Conda cheet sheet for reference if you need it: https://docs.conda.io/projects/conda/en/4.6.0/_downloads/52a95608c49671267e40c689e0bc00ca/conda-cheatsheet.pdf
You will need the Jupyter extension in vscode if you do not already have it installed.
You will also need to install the corresponding jupyter package in your conda environment.
I successfully installed the module geocoder:
Requirement already satisfied: chardet<5,>=3.0.2 in
c:\users\myname\appdata\roaming\python\python39\site-packages (from
requests->geocoder) (4.0.0) Installing collected packages: ratelim,
geocoder Successfully installed geocoder-1.38.1 ratelim-0.1.6
When I try to create a Python file that includes import geocoder, I get the error Import "geocoder" could not be resolved.
The relevant path is included in sys.path:
C:\Users\myname\Downloads
C:\Users\myname\AppData\Local\Programs\Python\Python39\python39.zip
C:\Users\myname\AppData\Local\Programs\Python\Python39\DLLs
C:\Users\myname\AppData\Local\Programs\Python\Python39\lib
C:\Users\myname\AppData\Local\Programs\Python\Python39
C:\Users\myname\AppData\Roaming\Python\Python39\site-packages
C:\Users\myname\AppData\Roaming\Python\Python39\site-packages\win32
C:\Users\myname\AppData\Roaming\Python\Python39\site-packages\win32\lib
C:\Users\myname\AppData\Roaming\Python\Python39\site-packages\Pythonwin
C:\Users\myname\AppData\Local\Programs\Python\Python39\lib\site-packages
C:\Users\myname\AppData\Local\Programs\Python\Python39\lib\site-packages\win32
C:\Users\myname\AppData\Local\Programs\Python\Python39\lib\site-packages\win32\lib
C:\Users\myname\AppData\Local\Programs\Python\Python39\lib\site-packages\Pythonwin
Why isn't Python able to resolve this module?
Thanks
Either geocoder is installed to other than Python3.9 version installation (e.g. python 3.7) or geocoder is not in the path of your python module.
Try to install the library using specific Python pip package manager (e.g. pip3.9) and run the module you develop using specific Python version (e.g. Python3.9)
I'm not using a virtual environment, & have tried selecting the appropriate python interpreter.
When I do a python3 -m pip install flask,
my terminal says Requirement already satisfied: MarkupSafe>=0.23 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from Jinja2>=2.10.1->flask) (1.1.1)
However, I receive this error message: ModuleNotFoundError: No module named 'flask' which traces back to VSCode being unable to import "flask" for some reason.
Would appreciate any help!
I am working on a raspberry pi python project and every time I import a package I get the same error ModuleNotFoundError: No module named ''. for example I am trying to add the ambient_api package
I followed the steps in their set up:
pip install ambient_api
Added the imports at the top of my file:
from ambient_api.ambientapi import AmbientAPI
api = AmbientAPI()
but I am getting the error:
ModuleNotFoundError: No module named 'ambient_api'
This is happening with all the imports I am trying to add and I cant figure out what I am missing.
when I was looking on google I came across __init__.py might be a solution but I am not sure how this works?
edit:
here is what was output when I installed:
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: ambient_api in /home/pi/.local/lib/python2.7/site-packages (1.5.2)
Requirement already satisfied: requests in /usr/lib/python2.7/dist-packages (from ambient_api) (2.21.0)
Requirement already satisfied: urllib3 in /usr/lib/python2.7/dist-packages (from ambient_api) (1.24.1)
version in my terminal:
pi#raspberrypi:~/Raspberry-Pi-Greenhouse $ python --version
Python 2.7.16
but it looks like the version in the shell in the ide when I run the program is saying:
Python 3.7.3 (/usr/bin/python3)
As explained by #JaFizz in Pytorch is installed but do not working ubuntu 18.04 it solved by giving an alias and installing correctly to desired python version (there were two pythons installed on the same machine)
First it was necessary to specify the location of the python, example:
alias python=/usr/local/bin/python3.6
Then install it:
python pip install <package name>
I am using Jupyter Notebook and trying to build a wordcloud. Turns out there are some issues with the pillow package and the internet is full of talks around it. I was geetting the DLL error initially. I tried a lot of different things and not sure which one worked but right now, I am getting the 'cannot import name' error.
Some details from Anaconda Prompt-
>python -m pip --version
pip 18.0 from C:\Users\Kritika.Jalan\Anaconda3\lib\site-packages\pip (python 3.6)
>python -m pip install wordcloud
Requirement already satisfied: wordcloud in c:\users\kritika.jalan\anaconda3\lib\site-packages (1.5.0)
Requirement already satisfied: numpy>=1.6.1 in c:\users\kritika.jalan\anaconda3\lib\site-packages (from wordcloud) (1.15.0)
Requirement already satisfied: pillow in c:\users\kritika.jalan\anaconda3\lib\site-packages (from wordcloud) (4.0.0)
Requirement already satisfied: olefile in c:\users\kritika.jalan\anaconda3\lib\site-packages (from pillow->wordcloud) (0.45.1)
Details from Jupyter Notebook -
from wordcloud import WordCloud
ImportError: cannot import name 'WordCloud'
import PIL
print(PIL.PILLOW_VERSION)
5.0.0
What am I doing wrong here?
Mostly, having a can not import name error even after successful library installation, is result of conflict with your local file name and python library name.
Do you have your own python file in your local named wordcloud.py ?
If yes, that is causing conflict with wordcloud.py in python library.
Simply rename your script.
Thanks
You just need to change your file name that is same to the library name