How to get Python3 to find installed module? - python-3.x

I'm attempting to install xlsxwriter on CentOS centos-release-7-6.1810.2.el7.centos.x86_64
when I install xlsxwriter:
703404669#bioitutil2:~$ sudo pip3 install xlsxwriter
Requirement already satisfied: xlsxwriter in /usr/lib64/python3.4/site-packages (1.2.6)
and when I attempt to load the module, I get a contradictory message:
703404669#bioitutil2:~$ python3
Python 3.6.8 (default, Aug 7 2019, 17:28:10)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import xlsxwriter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'xlsxwriter'
I've also tried pip3.6, but get more errors:
703404669#bioitutil2:~$ sudo pip3.6 install xlsxwriter
Traceback (most recent call last):
File "/bin/pip3.6", line 16, in <module>
sys.exit(main())
TypeError: 'module' object is not callable
How can I get python3 to find xlsxwriter?

pip3 install xlsxwriter
gives you
Requirement already satisfied: xlsxwriter in /usr/lib64/python3.4/site-packages (1.2.6)
so it is installed for python3.4, but python3 calls Python 3.6.8, so two different python versions that have their seperate site-package directory.
You can avoid this problem by doing python3 -m pip install, which should
Make sure that you are installing exactly for the python version you are intending to use
Avoid the 'module' object is not callable error
Note
I don't know how you ended up having two python versions, but it might be worth to check if you can uninstall one of them and then use a virtual environment or similar to manage multiple python versions on your system

Related

Why importing pyspark in python3 needs superuser access on my linux machine?

I installed pyspark using pip3.
Whenever I try import pyspark in python3 , I get an error:
import pyspark
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError:avinash#avinash-HP-ProBook-445-G1:~$ python3
Python 3.7.0 (default, Jun 28 2018, 13:15:42)
[GCC 7.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
import pyspark
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pyspark'
On the other hand when I use sudo python3, everything works fine!
A similar thing happens in Jupyter notebook also, I have to do sudo jupyter notebook --allow-root to import pyspark
However, importing other packages like numpy works fine without sudo too, that too installed with pip3.
Update: I installed pyspark using sudo pip3 install pyspark , I tried uninstalling it and then installing it without sudo i.e. pip3 install pyspark but it gives error:
Could not install packages due to an EnvironmentError: [Errno 13]
Permission denied:
'/usr/local/lib/python3.6/dist-packages/pyspark-2.4.0.dist-info'
Consider using the --user option or check the permissions.
Strange thing is, there is no file named 'pyspark-2.4.0.dist-info' as mentioned in error, in the directory /usr/local/lib/python3.6/dist-packages/pyspark-2.4.0.dist-info.
I also tried giving permission(777) to the above-mentioned directory.
Based on error you get, it seems you are using Anaconda on linux. In such a case you have to install pyspark using the command below:
conda install -c conda-forge pyspark

ModuleNotFoundError: No module named 'pandas.compat.numpy' Venv Py3.6.4, pandas 0.220

I'm stuck with a python virtual env installation and particularly pandas.
Pip list:
numpy (1.14.2)
pandas (0.22.0)
pip (9.0.1)
Python 3.6.4 (default, Mar 12 2018, 17:59:42)
[GCC 5.4.0 20160609] 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 "/home/me/tensorflow/lib/python3.6/site-packages/pandas/__init__.py", line 23, in <module>
from pandas.compat.numpy import *
ModuleNotFoundError: No module named 'pandas.compat.numpy'
>>>
You probably have several installations of pandas (using apt and using pip)
Remove all:
sudo apt-get purge python3-pandas
sudo pip3 uninstall pandas
Install using pip3:
sudo pip3 install pandas
Try the following and it should work
python3
>>import pandas

Something wrong with scikits.talkbox with Python3?

I am migrating a Python program from 2.10 to 3.6. The packages scikits.talkbox is part of it. However, I cannot figure out how to use it any more. The installation from pip seems to work fine but I cannot import it. Has anyone faced this problem before ?
[manjaro#manjaro-pc ~]$ python --version
Python 3.6.0
[manjaro#manjaro-pc ~]$ sudo pip install scikits.talkbox
Collecting scikits.talkbox
Using cached scikits.talkbox-0.2.5.tar.gz
Requirement already satisfied: numpy in /usr/lib/python3.6/site-packages (from scikits.talkbox)
Installing collected packages: scikits.talkbox
Running setup.py install for scikits.talkbox ... done
Successfully installed scikits.talkbox-0.2.5
[manjaro#manjaro-pc ~]$ python
Python 3.6.0 (default, Jan 16 2017, 12:12:55)
[GCC 6.3.1 20170109] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import scikits.talkbox
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.6/site-packages/scikits/talkbox/__init__.py", line 5, in <module>
__all__ += tools.__all__
AttributeError: module 'tools' has no attribute '__all__'
The answer to your question is this link Error while importing scikits.talkbox
Even I am facing this issue
I have switched to librosa
There is another way for MFCC features: python_speech_features
http://python-speech-features.readthedocs.io/en/latest/

Can't import paramiko in Python 3/Ubuntu

I installed the paramiko lib with Ubuntu's APT repositories (sudo apt-get install python3-paramiko), and I can't import it :
$ python3
Python 3.5.2 (default, Jul 5 2016, 12:43:10)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import paramiko
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'paramiko'
But when I install it with pip3 install paramiko, the import paramiko line works !
I could just stick with the pip version, but I want to distribute this program, and it would be very convenient to give all the dependencies as APT packages.
Why can Python import the pip version, but not the APT one ?
Maybe the apt package is installed to a dir not recognized by python3, that is, not in one of sys.path. compare the installed dir of python3-paramiko and the output of python3 -c 'import sys;print(sys.path)'.
Also, it's good practice for your python package to depend on packages installed by pip. Since you could distribute your package via setuptools and configure your dependency therein. Which make your program cross platform.

python3 tkinter ubuntu trusty does not work under virtual environment

I installed python3-tk on an ubuntu trusty docker container.(apt-get install python3-tk)
> python3
Python 3.4.3 (default, Oct 14 2015, 20:28:29)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>> import tkinter as tk
>>>
So far so good. However, for different reasons, I need to run a loaded python3 virtualenv in same container.
When I activate the virtual environment:
(env_py34)root#8a7953c24d4f:/home# python
Python 3.4.3 (default, Oct 14 2015, 20:28:29)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter as tk
Traceback (most recent call last):
File "/usr/lib/python3.4/tkinter/__init__.py", line 39, in <module>
import _tkinter
ImportError: No module named '_tkinter'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.4/tkinter/__init__.py", line 41, in <module>
raise ImportError(str(msg) + ', please install the python3-tk package')
ImportError: No module named '_tkinter', please install the python3-tk package
>>>
Versions of python are identical.
How come the virtual environment did not inherit python3-tk from the python3 installation? How can I install python3-tk inside the virtual environment?
So from the error message, python3-tk package is missed.
raise ImportError(str(msg) + ', please install the python3-tk package')
ImportError: No module named '_tkinter', please install the python3-tk package
Did you try to install it? for example, in ubuntu
sudo apt-get install python3-tk
I had the same problem. The answer provided by user BMW did not work for me. There is no need to recreate the virtualenv directory, like user1256124 suggests, although that is a perfectly workable solution as well.
Just use the bindings specific to the version of python that you need. For python3.6, this command is:
sudo apt-get install python3.6-tk
This allows an already set up virtualenv to find the right libraries.
I figured it out.
What was happening is that once python3 virtualenv was created there was no more inheriting to be done from the python3 apt-get installation.
Once I recreated the image from the updated Dockerfile in which it was specified to apt-get install python3-tk BEFORE creating the python3 virtualenv, then everything worked.
Not sure why this is the case though.

Resources