Can't import paramiko in Python 3/Ubuntu - python-3.x

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.

Related

Python3-tk is already installed but python3.7 can't find module tkinter

I am using some python3.7 code that is running tensorflow under the hood. When I run it I get the following error:
import tkinter as Tk
ModuleNotFoundError: No module named 'tkinter'
I did some googling and found that I need to install python3-tk so I ran the following command:
sudo apt-get install python3-tk
and get the following output confirming that it is installed:
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-tk is already the newest version (3.5.1-1).
0 upgraded, 0 newly installed, 0 to remove and 108 not upgraded.
Yet when I get into my python3.7 interpreter and test it with the following commands
$python3.7
>> import tkinter
I get the following output saying it is not installed:
$ python3.7
Python 3.7.3 (default, Mar 26 2019, 01:59:45)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'tkinter'
How do I go about getting tkinter to run on python3.7 when apt already thinks it is installed? As a side not I am on Ubuntu 16.
#davedwards solved this problem with the following command:
sudo apt-get install python3.7-tk

ModuleNotFoundError when importing package that is installed in conda environment

Unable to import flask-migrate dependencies that are missing python version/sub-version from build version (3rd column of conda list output).
Flask-migrate was installed from conda-forge using:
conda install -c conda-forge flask-migrate
Several dependencies were installed simultaneously and are found in conda list -n venv but cannot be imported to python.
(venv) C:\Users\Colin\Documents\Projects\microblog>python
Python 3.6.8 |Anaconda, Inc.| (default, Feb 21 2019, 18:30:04) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import alembic
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'alembic'
From what I have found, the packages that are raising ModuleNotFoundErrors upon import are all missing the python version in the 3rd column of conda list.
Successfully import: py36_0 or py36_1000 or py36* etc.
ModuleNotFoundError: py_0 or py_1
Why are installed packages raising ModuleNotFoundError when imported to python?
I believe the packages with py_0 environment were all installed as Noarch packages from conda. I'm not sure why my system is unable to import the Noarch packages but I was able to work around the problem by manually downloading the win64-py36_0.tar.bz2 files and installing them locally using:
conda install /package-path/package-filename.tar.bz2

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/

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.

OpenShift Python3.3 Cartridge trouble upgrading numpy/installing scipy

I have an OpenShift gear with a python3.3 cartridge. On this, I am attempting to install Scipy. I have tried the simplest method of simply putting scipy in the install_requires field of the setup.py file.
This did not work, I get the error:
ImportError: No module named 'numpy.f2py'
Okay so perhaps I need to upgrade my version of numpy. I try the obvious again of changing numpy to numpy==1.8.2 in the install_requires field of the setup command. This appears to install fine, but I get the same error from the installation of scipy.
Okay, so now I try ssh-ing into my openshift gear (rhc ssh app-name). I try the first thing to simply pip install scipy, and I basically get the same error:
$ source ~/python/virtenv/venv/bin/activate
(venv) $ pip install scipy
...
ImportError: No module named 'numpy.f2py'
Cleaning up ...
...
Okay so I try a pip freeze:
(venv) $ pip freeze
...
numpy=1.7.2
...
Similarly:
(venv) $ python
Python 3.3.2 (default, Mar 20 2014, 20:25:51)
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy.f2py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'numpy.f2py'
Okay so let's try forcing the upgrade:
(venv) $ pip install --upgrade -I numpy
.... success ....
(venv) $ pip freeze
...
numpy=1.7.2
Hmm. I try it with and without the -I and with and without numpy==1.8.2. Each with the same result. Numpy really wants to stay at the globally installed version. Now if I look into the lib directory I see:
(venv) $ ls ~/python/virtenv/venv/lib/python3.3/site-packages
bottle-0.12.7-py3.3.egg pip-1.5.6.dist-info
docopt-0.6.2-py3.3.egg __pycache__
easy-install.pth pyparsing-2.0.2-py3.3.egg
Jinja2-2.7.3-py3.3.egg SQLAlchemy-0.9.7-py3.3-linux-x86_64.egg
lazy-1.2-py3.3.egg virtualenv-1.11.6.dist-info
...
Okay so basically every package I have in my install_requires field of the setup.py other than numpy. So now I look in the lib64 directory:
(venv) $ ls ~/python/virtenv/venv/lib64/python3.3/site-packages
numpy numpy-1.8.0-py3.3.egg-info numpy-1.8.1-py3.3.egg-info numpy-1.8.2-py3.3.egg-info
So basically every upgraded version of numpy I have attempted to install (which have reported success). So, how do I get pip freeze to see into this directory? I guess more generally I need the pip echo-system and python to see the installed packages in this directory.
Or alternatively, what am I doing wrong?

Resources