I have been using Jupyter notebook in AWS EMR when I run a program which requires graphical representations. I get this error:
No module named 'tkinter'
Traceback (most recent call last):
File "/usr/local/lib/python3.4/site-packages/seaborn/__init__.py", line
6, in <module>
from .rcmod import *
File "/usr/local/lib/python3.4/site-packages/seaborn/rcmod.py", line 5,
in <module>
from . import palettes, _orig_rc_params
File "/usr/local/lib/python3.4/site-packages/seaborn/palettes.py", line 12, in <module>
from .utils import desaturate, set_hls_values, get_color_cycle
File "/usr/local/lib/python3.4/site-packages/seaborn/utils.py", line 11, in <module>
import matplotlib.pyplot as plt
File "/usr/local/lib64/python3.4/site-packages/matplotlib/pyplot.py", line 115, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/usr/local/lib64/python3.4/site-packages/matplotlib/backends/__init__.py", line 62, in pylab_setup
[backend_name], 0)
File "/usr/local/lib64/python3.4/site-packages/matplotlib/backends/backend_tkagg.py", line 4, in <module>
from . import tkagg # Paint image to Tk photo blitter extension.
File "/usr/local/lib64/python3.4/site-packages/matplotlib/backends/tkagg.py", line 5, in <module>
from six.moves import tkinter as Tk
File "/usr/local/lib/python3.4/site-packages/six.py", line 92, in __get__
result = self._resolve()
File "/usr/local/lib/python3.4/site-packages/six.py", line 115, in _resolve
return _import_module(self.mod)
File "/usr/local/lib/python3.4/site-packages/six.py", line 82, in _import_module
__import__(name)
ImportError: No module named 'tkinter'
You should run matplotlib with a non-interactive backend on a EC2 server as EC2 is headless. Configure your matplotlibrc file with this line.
backend : agg
To know more about this file, follow this link.
I believe you need to install the python3-tk module. If you're using a debian-based distro then run apt-get install python3-tk from the command line.
I just looked at this on a CentOS 7 VM (closest thing to your environment that I have set up right now). Because you are not using a software collection (definitely recommended), it looks like Tkinter can be installed with:
sudo yum install python33-python-tkinter.x86_64
But it looks like that is for Python 3.3 whereas you are using Python 3.4, so I'd suggest trying:
sudo yum install python34-python-tkinter.x86_64
Finding Packages
If that does not work, the easiest way I know of to find the appropriate package is to do:
yum search tkinter | less
...and see what packages that turns up.
Software Collection
If you go the route of software collections, you would need to install the appropriate Python distribution (see the Software Collections site here), then install the appropriate tkinter version. For me, yum search tkinter brings up:
...
rh-python34-python-tkinter.x86_64
rh-python35-python-tkinter.x86_64
rh-python36-python-tkinter.x86_64
...
These are for the software collections and correspond to Python 3.4, 3.5, and 3.6.
Related
I'm trying to use mayavi in python to visualize a pointcloud, and cannot resolve this error. I'm sure it is an easy pip install, but I am unsure of the command. Any help is much appreciated! Thanks!
BTW, I am running Ubuntu 18.04 and have tried installing scipy as mentioned here: Python import error "getfullargspec". I have also ran pip install traitsui. Additionally, I have rebooted my system.
Update:
After further digging, it appears that it may be an issue with Python versions. I was able to get it to run with Python3, but not Python 2.7 (I need it to work with python 2). I have also tried modifying the code within handler.py to getargspec instead of getfullargspec. I was given an error about trait_factory by doing this
Here is the entire printout:
Traceback (most recent call last):
File "mayavi_test.py", line 3, in <module>
from mayavi import mlab
File "/home/user/.local/lib/python2.7/site-packages/mayavi/mlab.py", line 16, in <module>
from mayavi.tools.camera import view, roll, yaw, pitch, move
File "/home/user/.local/lib/python2.7/site-packages/mayavi/tools/camera.py", line 24, in <module>
from .engine_manager import get_engine
File "/home/user/.local/lib/python2.7/site-packages/mayavi/tools/engine_manager.py", line 12, in <module>
from mayavi.preferences.api import preference_manager
File "/home/user/.local/lib/python2.7/site-packages/mayavi/preferences/api.py", line 4, in <module>
from .preference_manager import preference_manager
File "/home/user/.local/lib/python2.7/site-packages/mayavi/preferences/preference_manager.py", line 29, in <module>
from traitsui.api import View, Group, Item
File "/home/user/.local/lib/python2.7/site-packages/traitsui/api.py", line 37, in <module>
from .editors.api import (
File "/home/user/.local/lib/python2.7/site-packages/traitsui/editors/__init__.py", line 26, in <module>
from .api import (
File "/home/user/.local/lib/python2.7/site-packages/traitsui/editors/api.py", line 6, in <module>
from .array_editor import ArrayEditor
File "/home/user/.local/lib/python2.7/site-packages/traitsui/editors/array_editor.py", line 34, in <module>
from ..view import View
File "/home/user/.local/lib/python2.7/site-packages/traitsui/view.py", line 41, in <module>
from .ui import UI
File "/home/user/.local/lib/python2.7/site-packages/traitsui/ui.py", line 51, in <module>
from .handler import Handler, ViewHandler
File "/home/user/.local/lib/python2.7/site-packages/traitsui/handler.py", line 27, in <module>
from inspect import getfullargspec
ImportError: cannot import name getfullargspec
The solution for this problem was to use older packages. Not all of the dependencies such as traitsui are compatible with Python 2.7. Even though an older version of mayavi was installed, the dependencies that are installed automatically are not compatible (they only support Python 3).
Here are the versions that work well together for me:
mayavi==4.6.2
traitsui==6.1.3
traits==5.2.0
numpy==1.17.4
pyface==6.1.2
To install a specific version, just run sudo pip install packageName==#.#.#
I found 0 topics about this issue for Windows, only for Ubuntu, MAc etc.
When I try to install any package via Pycharm, e.g. urllib, matplotlib, heidi, I get the exact same error message as below.
Project interpreter is Anaconda Python 3.7.
Any idea how this can solved?
Error: Traceback (most recent call last):
File "E:\Download\PROGIK\Charm Community Edition 2018.3.5\helpers\packaging_tool.py", line 73, in run_pip
runpy.run_module(module_name, run_name='__main__', alter_sys=True)
File "E:\Download\PROGIK\Anaconda\lib\runpy.py", line 201, in run_module
mod_name, mod_spec, code = _get_module_details(mod_name)
File "E:\Download\PROGIK\Anaconda\lib\runpy.py", line 142, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "E:\Download\PROGIK\Anaconda\lib\runpy.py", line 109, in _get_module_details
__import__(pkg_name)
File "E:\Download\PROGIK\Anaconda\lib\site-packages\pip\__init__.py", line 15, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "E:\Download\PROGIK\Anaconda\lib\site-packages\pip\vcs\subversion.py", line 9, in <module>
from pip.index import Link
File "E:\Download\PROGIK\Anaconda\lib\site-packages\pip\index.py", line 30, in <module>
from pip.wheel import Wheel, wheel_ext
File "E:\Download\PROGIK\Anaconda\lib\site-packages\pip\wheel.py", line 35, in <module>
from pip._vendor.distlib.scripts import ScriptMaker
File "E:\Download\PROGIK\Anaconda\lib\site-packages\pip\_vendor\distlib\scripts.py", line 14, in <module>
from .compat import sysconfig, detect_encoding, ZipFile
File "E:\Download\PROGIK\Anaconda\lib\site-packages\pip\_vendor\distlib\compat.py", line 66, in <module>
from urllib.request import (urlopen, urlretrieve, Request, url2pathname,
ImportError: cannot import name 'HTTPSHandler' from 'urllib.request' (E:\Download\PROGIK\Anaconda\lib\urllib\request.py)
Edit: with pip I have only problem with matplotlib, which is another topic:
Cannot install matplotlib. Fatal error LNK1181, Visual Studio fail
Simply went into packages folder and deleted matplotlib package manually because could not make it display graphs in Jupyter (didnt try in Pycharm). Trying to reinstall it now, hopefully it will fix the issue.
To install packages whithin anaconda environment under Windows10, you should use "Anaconda prompt" (find it in win menu)
It starts (Base) venv by default and installs packages in it. Therefore using Python interpreter distributed with Anaconda you will be able to import them with no side actions.
Besides matplotlib is installed there by default
I have set up a virtual environment and when I try to run matplotlib on it, I get the following error:
Traceback (most recent call last):
File "/Users/sumeet/PycharmProjects/VISM/test2.py", line 2, in <module>
import matplotlib.pyplot as plt
File "/Users/sumeet/tensorflow/lib/python2.7/site-packages/matplotlib/pyplot.py", line 115, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/Users/sumeet/tensorflow/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 62, in pylab_setup
[backend_name], 0)
File "/Users/sumeet/tensorflow/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 4, in <module>
from . import tkagg # Paint image to Tk photo blitter extension.
File "/Users/sumeet/tensorflow/lib/python2.7/site-packages/matplotlib/backends/tkagg.py", line 5, in <module>
from six.moves import tkinter as Tk
File "/usr/local/Cellar/python/2.7.14_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/six.py", line 203, in load_module
mod = mod._resolve()
File "/usr/local/Cellar/python/2.7.14_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/six.py", line 115, in _resolve
return _import_module(self.mod)
File "/usr/local/Cellar/python/2.7.14_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/six.py", line 82, in _import_module
__import__(name)
File "/usr/local/Cellar/python/2.7.14_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 39, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
From what I understand, I need to
set the environment variables correctly in the activate script
or I can symlink tkinter folder to virtualenv python2.7.
I have followed the steps here: TKinter in a Virtualenv, but I am still getting the error.
Steps that I followed are:
To virtualenv/bin/activate, I added
TK_LIBRARY=/usr/lib/python2.7/lib-tk:/usr/lib/python2.7/site-packages/PIL:/usr/lib
TKPATH=/usr/lib/python2.7/lib-tk:/usr/lib/python2.7/site-packages/PIL:/usr/lib
TCL_LIBRARY=/usr/lib
export TCL_LIBRARY TK_LIBRARY TKPATH
In virtualenv/lib/python2.7 I ran, ln -s /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_tkinter.so
Note that when I am using the system Python as an interpreter on PyCharm, matplotlib works fine which gives me a feeling that Tkinter is available somewhere on my system but I am failing to call it from my virtual environment.
The link above seems to be working for Ubuntu. I am wondering if anyone know what is the analogous version for Mac.
Thanks!
If you are not specific to using tkinter in virtual environment then you can use the following lines of code:
import matplotlib
matplotlib.use(‘TkAgg’)
import matplotlib.pyplot as plt
I hope this solves the problem.
I tried to smoothly pass from python 2.7 to python 3.X (3.5.2). This is a two-step question so I tried to make it clear.
1. I made a simple trial with
import numpy as np
(I did a python3 -m pip install numpy first) But I received the following error message
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 180, in <module>
from . import add_newdocs
File "/usr/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/lib/python2.7/dist-packages/numpy/core/__init__.py", line 14, in <module>
from . import multiarray
ImportError: cannot import name 'multiarray'
Is the erorr somehow connected with python2.7 ?
2. When I tried to import modules I already installed (pip install module) python3 do not find them (ImportError: No module named ...). In this second case I think that the directory in which I install the modules is connected with python 2.7.
How can I point python3 to modules I already have? My dream is to avoid using python3 -m pip install ModuleName, I would like to not reinstall each single modules by hands (I also do not remember which I have and why :) ).
I am using Ubuntu 16.04.1 LTS.
In my .bashrc I have the following segment, maybe is not important, but I try to give more informations as possible
# added by me for the python import module installed outside anaconda2 (i.e.: pygtk)
export PYTHONPATH="${PYTHONPATH}:/usr/lib/python2.7/dist-packages/"
export PYTHONPATH="${PYTHONPATH}:/usr/lib/python2.7/dist-packages/glib/"
Many thanks.
You should definitely not have those lines in your .bashrc. Remove them and start a new shell.
And no, you need to reinstall the modules you need for Python3.
I have installed Django 1.6.5 with PIP and Python 2.7.8 from the website.
I ran django-admin.py startproject test123, switched to test123 directory, and ran the command python manage.py runserver, then i get this:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/core/management/__init__.py", line 261, in fetch_command
commands = get_commands()
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/core/management/__init__.py", line 107, in get_commands
apps = settings.INSTALLED_APPS
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/conf/__init__.py", line 50, in _setup
self._configure_logging()
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/conf/__init__.py", line 72, in _configure_logging
from django.utils.log import DEFAULT_LOGGING
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/utils/log.py", line 7, in <module>
from django.views.debug import ExceptionReporter, get_exception_reporter_filter
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/views/debug.py", line 10, in <module>
from django.http import (HttpResponse, HttpResponseServerError,
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/http/__init__.py", line 2, in <module>
from django.http.request import (HttpRequest, QueryDict, UnreadablePostError,
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/http/request.py", line 11, in <module>
from django.core import signing
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/core/signing.py", line 45, in <module>
from django.utils.crypto import constant_time_compare, salted_hmac
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/utils/crypto.py", line 6, in <module>
import hmac
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hmac.py", line 8, in <module>
from operator import _compare_digest as compare_digest
ImportError: cannot import name _compare_digest
Found out that operator is a standard python library. Why cant it not import it?
P.S. I did try it in the command line, I can import the operator module, but I get an error on this statement: from operator import _compare_digest as compare_digest
Followed this SO answer:
Uninstall python.org version of python2.7 in favor of default OS X python2.7
Then changed my .bash_profile Python path to /usr/lib/python for the default OSX python path.
Uninstalled Django and MySQL-Python:
sudo pip uninstall django
sudo pip uninstall MySQL-Python
And then again reinstalled everything, but with MySQL-Python being the first and second Django.
After these steps, everything is working.
I get this error with anaconda as my default python and django1.7 while trying to use startproject.
I deleted the venv and recreated it with
virtualenv -p /usr/bin/python2.7 venv
startproject was working again.
You most likely have another file named operator.py on your PYTHONPATH (probably in the current working directory), which shadows the standard library operator module..
Remove or rename the file.
For those not wanting to switch to Apple's python, simply deleting the virtualenv and rebuilding it worked fine for me.
Tip: Don't forget to pip freeze > requirements.txt first if you aren't already tracking your package requirements. That way you can pip install -r requirements.txt to get up and running again quickly.