I'm trying to read a .xlxs file in Python using xlrd, but I keep getting the error Unable to import xlrd.
When I try to re-install xlrd using:
pip install xlrd
I keep getting the message
Requirement already satisfied: xlrd in ./anaconda3/lib/python3.6/site-packages (1.1.0)
And my error message after running my code is
Traceback (most recent call last):
File "/Users/YoungFreeesh/Venture Capital Internship/.../.../Read-csv.py", line 2, in <module>
import xlrd # import the xlrd module
ImportError: No module named xlrd
Also, not sure if this is relevant but I'm using Visual Studio & Python 3.6.5
I'm not sure why I can't import xlrd since I already have it downloaded.
I ran into a similar issue. Make sure you're pip installing the right version (3.x or 2.x). If you're using Python 3, pip3 install xlrd will make sure it is installed and accessible when running Python3 code.
Related
So I am using VS code on Mac. I'd like to read .xls file on python. I have installed openpyxl package using code: python3 -m pip install openpyxl. But when I try to run import openpyxl, I get an error: ImportError: No module named openpyxl. When I tried to install the package once more, I got a message: Requirement already satisfied: openpyxl in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages.
So I don't know, why the package can't be imported. Can anyone help me out?
UPDATE: Thank you to everyone who answered and commented. I understand now that I have 2 versions of python installed. My program was running from "Miniconda3/python.exe ". While bs4 was installed in "c:\python38\lib\site-packages". I understand this to be the cause of the problem. I removed Minicoda3 but VS code still tries to use it when I run a program. How can I fix this?
When I run the following code:
>>> from bs4 import BeautifulSoup
Error:
I get the error: "No module named 'bs4'.
After I install bs4, It says "Requirement already satisfied" yet I get the same error.
Im not sure what I'm doing wrong, please help. Error messages below.
PS C:\Users\Admin\Desktop\exAPP> pip install bs4
Collecting bs4
Requirement already satisfied: beautifulsoup4 in c:\python38\lib\site-packages (from bs4) (4.9.1)
Requirement already satisfied: soupsieve>1.2 in c:\python38\lib\site-packages (from beautifulsoup4->bs4) (2.0.1)
Using legacy setup.py install for bs4, since package 'wheel' is not installed.
Installing collected packages: bs4
Successfully installed bs4-0.0.1
PS C:\Users\Admin\Desktop\exAPP> & C:/Users/Admin/Miniconda3/python.exe c:/Users/Admin/Desktop/JNB.py
Traceback (most recent call last):
File "c:/Users/Admin/Desktop/JNB.py", line 2, in <module>
import BeautifulSoup
ModuleNotFoundError: No module named 'BeautifulSoup'
PS C:\Users\Admin\Desktop\exAPP> & C:/Users/Admin/Miniconda3/python.exe c:/Users/Admin/Desktop/JNB.py
Traceback (most recent call last):
File "c:/Users/Admin/Desktop/JNB.py", line 2, in <module>
from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'
PS C:\Users\Admin\Desktop\exAPP>
You are using miniconda, which might not be on your PATH correctly such that pip is actually part of a separate Python installation.
You could use conda install pip, or C:/Users/Admin/Miniconda3/python.exe -m pip install bs4
Okay so my problems are fixed an my program is running. Like I said in the update the first problem was due to having 2 versions of python installed. After I removed the unwanted version it was still set as the python interpreter path. I was trying to fix this by going into VS code settings but was having no luck. Fortunately I finally noticed there was a button on bottom left of the screen that allowed me to change the path easily. Thanks again to those who commented and answered.
I am very new to Python and have reviewed multiple questions here on problems getting packages/modules to import but can't seem to work out what I'm doing wrong. I'm simply trying to import packages and use them in the Spyder console, I'm used to working in R Studio so that's kind of my point of reference.
I run the below code and receive the following messages.
pip install Pillow
Requirement already satisfied: Pillow in c:\users\name\anaconda3\lib\site-packages (7.0.0)
Note: you may need to restart the kernel to use updated packages.
import Pillow
Traceback (most recent call last):
File "<ipython-input-7-f4cbff62aba7>", line 1, in <module>
import Pillow
ModuleNotFoundError: No module named 'Pillow'
I also seem to be getting different results when I run pip install from the console vs from the text editor portion. When I run it from the console, I get the above result about it already being installed. When I run it from the text editor portion, I get the following.
runcell(0, 'C:/Users/name/.spyder-py3/temp.py')
File "C:\Users\name\.spyder-py3\temp.py", line 1
pip install Pillow
^
SyntaxError: invalid syntax
I'm trying to use opencv-python. I imported with pip but it throws ModuleNotFound.
Joshua-Tews-MacBook-Pro:~ nathan$ pip install opencv-python
Requirement already satisfied: opencv-python in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (4.0.0.21)
Requirement already satisfied: numpy>=1.14.5 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from opencv-python) (1.16.2)
I import with this:
import cv2
I get this error:
Traceback (most recent call last):
File "/Users/nathan/Library/Mobile Documents/com~apple~CloudDocs/CEP/Y4/Capstone Project (Security Cameras System)/cep-ml-capstone/VideoProcessor.py", line 1, in <module>
import cv2
ModuleNotFoundError: No module named 'cv2'
I've look at the answers on this stackoverflow thread, none seem to help: Cannot import cv2 in python in OSX
Others have solutions I completely didn't recognise pertaining to other OS so I skipped those.
Okay I apparently I just had to run the script with Python 3.7 and it worked. I neglected to mention I was using Textmate.
To run scripts in Python 3.7 using Textmate, go to Preferences > Variables. If there isn't a variable named TM_PYTHON, create one then paste this in for the value: /Library/Frameworks/Python.framework/Versions/3.7/bin/python3. Else, just change the value. Be sure to check the box next to the variable.
I'm trying to work on some excel files, I decided to use openpyxl library. I've copied the openpyxl folder to /Lib/ and trying to do the import command on some sample code, and all I get is a list of few errors.
Traceback (most recent call last):
File "C:/Users/Karolina/Documents/python/test xlsx.py", line 1, in <module>
import openpyxl
File "C:\Python34\lib\openpyxl\__init__.py", line 9, in <module>
from openpyxl.workbook import Workbook
File "C:\Python34\lib\openpyxl\workbook\__init__.py", line 5, in <module>
from .workbook import *
File "C:\Python34\lib\openpyxl\workbook\workbook.py", line 14, in <module>
from openpyxl.utils.datetime import CALENDAR_WINDOWS_1900
File "C:\Python34\lib\openpyxl\utils\datetime.py", line 11, in <module>
from jdcal import (
ImportError: cannot import name 'gcal2jd'
First I was getting the same error about "jdcal" so I have installed the library called jdcal. Now I have no clue how to fix this one, what is wrong with it?
I'm using python 3.4
openpyxl module has 2 dependent modules :
1. jdcal
2. et_xmlfile
I was able to install openpyxl module and this is what I did :
Downloaded the openpyxl,jdcal and et_xmlfile from
https://pypi.python.org/pypi and saved jdcal-1.0.tar.gz,
et_xmlfile-1.0.0.tar.gz,openpyxl-2.3.0-b2.tar.gz in a local folder
in my system.
Then I ran the commands in the following order :
pip install jdcal-1.0.tar.gz
pip install et_xmlfile-1.0.0.tar.gz
pip install openpyxl-2.3.0-b2.tar.gz
openpyxl got successfully after this.
Actually openpyxl depends upon jdcal & et_xmlfile. You first require to install these two packages. I have managed to run openpyxl by downloading and giving refrencing some thing like this:
#For Writing in Excel File
import sys
#For openpyxl-2.4.0 Python Package you should need to have et_xmlfile and jdcal package
sys.path.append("D:\et_xmlfile-1.0.1")
sys.path.append("D:\jdcal-1.3")
sys.path.append('D:\openpyxl-2.4.0')
import openpyxl
I was same problem. I solved it :) .
if you have pip3 or other you can simple download and install from your terminal:-
sudo pip3 pip3 install jdcal
sudo pip3 install et_xmlfile