Python : issue running XLRD - python

I'm testing newly installed 'xlrd' package :
#!/usr/bin/env/python
import xlrd
wb = xlrd.open_workbook('D:\excel\test.xls')
print (wb.sheets())
I run it through IDLE (Windows 7) and I get the following error message:
Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:19:30) [MSC v.1600 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
Traceback (most recent call last):
File "D:\excel\testxls.py", line 3, in <module>
import xlrd
File "C:\Program Files (x86)\Python33\lib\site-packages\xlrd\__init__.py", line 1187
print "EXTERNSHEET(b7-):"
^
SyntaxError: invalid syntax
>>>
Any idea on this issue?
Thanks!

It seems like your xlrd file is corrupted. So update it by using the following command :
$ python3 -m pip install --upgrade xlrd

XLRD is available for Python3.
You can get it with sudo apt-get install python3-xlrd or with sudo pip3 install xlrd
As you can see it's available here on pypi : https://pypi.python.org/pypi/xlrd
Here's a dump of my console output :
sudo apt-get install python3-xlrd
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-xlrd is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 574 not upgraded.

It seems that there is an error with your installation or usage.
The first thing I have seen is that print 'something' is not used in python3 but print('something'). And the error shown in the code is because of using python2 with python3.
At the time of writing this answer the version of xlrd is 0.9.4. This version is compatible with both python2 and python3.
So I suggest you to update the xlrd module so that you will not face any further errors. You can do that by following any of the following steps:
$ pip install xlrd
or
$ easy_install xlrd

Related

Python 3: ModuleNotFoundError: No module named 'pandas.util' (raspberry pi)

Am having issues importing pandas on python3 on my raspberry pi. Whatever I try, I get the following error:
pi#raspberrypi:/ $ python3
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/dist-packages/pandas/__init__.py", line 22, in <module>
from pandas.compat import (
File "/usr/local/lib/python3.7/dist-packages/pandas/compat/__init__.py", line 15, in <module>
from pandas.compat.numpy import (
File "/usr/local/lib/python3.7/dist-packages/pandas/compat/numpy/__init__.py", line 7, in <module>
from pandas.util.version import Version
ModuleNotFoundError: No module named 'pandas.util'
It works fine on Python 2.7. I am getting errors with Python 3.7.3.
I searched Google and tried everything in the following post:
ImportError: No module named pandas
Some of the things I’ve tried are below - none have helped - I still get the error.
pip3 install pandas-util
pip3 install pandas.util
sudo apt-get install python3-wheel
sudo python3 -m pip install pandas
pip3 install pandas --upgrade
I've also tried uninstalling and reinstalling numpy and pandas - still get this error just with a basic import statement.
Any help would be appreciated as this is driving me insane!!
Cheers!
Try with
python3 -m pip install --force-reinstall pandas
This will ensure two things:
it will use the pip executable that belongs to the used Python executable, so that there is no accidental installation by another pip.
it will properly re-install Pandas.
Note that it doesn't re-download the Pandas package (it will use a cached version) if the version on PyPI hasn't changed between now and the previous installation. If that is a potential problem (incorrect cached file, for example), add the option --no-cache-dir to pip install.

Trying to test my python library, it's installed but not found

When I try to install my library locally and test it, it shows up as installed:
PS C:\Projects\pypi\potatoutils> pip install -e .
Obtaining file:///C:/Projects/pypi/potatoutils
Installing collected packages: potatoutils
Attempting uninstall: potatoutils
Found existing installation: potatoutils 0.0.1
Uninstalling potatoutils-0.0.1:
Successfully uninstalled potatoutils-0.0.1
Running setup.py develop for potatoutils
Successfully installed potatoutils
But when I try to test it
PS C:\Projects\pypi\potatoutils> python
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import potatoutils
I get this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'potatoutils'
What am I doing wrong?
EDIT: pip and python have the same version (3.7) and their paths match.
And the library shows up when I use pip list.
Often this is the issue if you pip install a package with pip for python2.x
but then when you attempt to import your library for python3.x
Make sure you're running installing pip packages for the correct python version.
use pip3 using pip sometimes point to python 2.x versions, that's why maybe it can help!
Okay, so I managed to get the library up and running by starting over and following these instructions:
https://medium.com/analytics-vidhya/how-to-create-a-python-library-7d5aea80cc3f
I still don't know what went wrong the first time (maybe outdated instructions?) but it no longer matters to me.

matplotlib works with default python but not python3.5 on debian

I have this issue. I think it's best described when I show you my bash commands that I used to produce the problem. See here:
josch#oogway:~$ python
Python 2.7.9 (default, Jun 29 2016, 13:08:31)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> #works
josch#oogway:~$ python3.5
Python 3.5.0 (default, Apr 26 2017, 21:03:53)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'matplotlib'
>>> #what??
Matplotlib was installed by:
sudo apt-get install python-matplotlib
The "default" python came with my OS installation, python3.5 was downloaded and then compiled/installed from source.
Can anyone help? Tried to solve it myselve for 2 hours now but google can't find answer
Edit: I'm trying to install a "second pip" that works with my second installation of Python, which is Python3.5. My default-Python that is managed by the OS is Python 2.7.9. Now, as suggested I did:
joschua#oogway:~/Downloads$ wget https://bootstrap.pypa.io/get-pip.py
and then:
python3.5 get-pip.py
which gave me:
joschua#oogway:~/Downloads$ python3.5 get-pip.py
Traceback (most recent call last):
File "get-pip.py", line 20061, in <module>
main()
File "get-pip.py", line 194, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 82, in bootstrap
import pip
zipimport.ZipImportError: can't decompress data; zlib not available
Try installing pip3 with:
sudo apt-get install python3-pip
and then try installing matplotlib with:
sudo pip3 install matplotlib
I actually could solve the problem now.
See this link for a reasonable description on how to run two different versions of python on the same system (and as #Pierre de Buyl suggested) use two different pip versions on the same system
https://www.linkedin.com/pulse/20140815081557-89781742-how-to-install-and-use-python-with-different-versions-on-same-linux-machine
So, you installed python3.5 from source. What version of Debian are you using? (I suppose Jessie).
If you want to install packages for this Python interpreter, you must have a pip that actually uses it. Two solutions:
It is installed. If so,
python3.5 -m pip
will work and you can install packages with
python3.5 -m pip install matplotlib
or
python3.5 -m pip install --user matplotlib
It is not installed. You must install it following the instructions at https://packaging.python.org/installing/#requirements-for-installing-packages
apt-get will not install the appropriate pip for your needs. It will only install a pip that is related to the python3 (3.4 for jessie I believe) that is also in the apt-get system.
EDIT: in light of the update, you need also to re-compile python3.5 with zip enabled.

Why doesn't Ubuntu install matplotlib for my correct python version?

When I type in which python I get /usr/bin/python as expected. However, I wanted to install matplotlib and running sudo apt-get install python-matplotlib says
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-matplotlib is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
Fair enough, I thought that the library was installed, but when I tried to import it I got an error:
[ivaylo#ivaylo-K55VD ~]$ python
Python 2.7.9 (default, Apr 24 2015, 12:56:53)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named matplotlib
>>>
So it turns out I have matplotlib installed for my default implementation, yet it cannot be found. I checked the contents of /usr/bin/ and there are multiple python executables:
python refers to, as you can see, version 2.7.9 and is the only version where matplotlib is not available.
python2 python2.7 and python2.7.6 all map to version 2.7.6 and there the library is available.
python3 and python3.4 map to version 3.4.3 where matplotlib is also available, but only after I installed it with sudo apt-get install python3-matplotlib.
So my question is, why is the default python 2.7.9 and why doesn't apt install the library for the correct version?
My Ubuntu is 14.04 if that matters.

I can't find python package fftw3

I'm trying to use fftw3 on python to compute ffts really fast (using all my cores!)
The problem is... I can't find the fftw3 package for python...
I know it exists because the function I need uses it if and only if it's installed.
This is the module that I use: https://github.com/keflavich/image_tools/blob/master/fft_psd_tools/convolve_nd.py
And as expected this is what I get if I try to import it:
>>> import fftw3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named fftw3
>>>
And I've tried this:
sudo pip install fftw3
sudo apt-get install python-fftw3
sudo easy_install fftw3
And I have also tried googling for its location, or installation instructions, with nothing to be found!
I am also aware that fftw is a C library and that pyfftw exists as python wrappers for that package, but the function I use utilizes fftw3.
I am hoping someone could point me to where this module is located!
P.S. I am running Ubuntu 14.04 and I'm using python 2.7. I also tried importing it in python 3 but it's not there either.
Looks like the problem was with the package you were trying to pip. I had no errors with sudo pip install pyfftw3 then import fftw3
will#will-mint2 ~ $ sudo pip install pyfftw3
[sudo] password for will:
Downloading/unpacking pyfftw3
Downloading PyFFTW3-0.2.1.tar.gz
...
Successfully installed pyfftw3
Cleaning up...
will#will-mint2 ~ $ python
Python 2.7.9 (default, Mar 1 2015, 12:57:24)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import fftw3
>>> exit()
For windows
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyfftw
install it by:
pip install [filename].whl
import in your code by
import pyfftw as fftw

Categories