I have installed Tcl and Tk, and I am running into the oh-so-familiar "No module named _tkinter" error.
My 'python' Bash command runs Python version 2.4.2, but Synaptic says I have 2.6.6 installed. I even tried installing 3.0, but that also failed.
I have configured and built the Tcl/Tk tarballs myself, and tried using the synaptic packages.
Both "wish" and "tclsh" commands work, so I know that the modules are installed, but I can't for the life of me get Python to recognize them. Moreover, I can't for the life of my figure out which version of Python I should be using and how to get my Bash command to use that one.
I don't see any options for 2.4.2 removal, and if I remove 2.6.6, it removes what seems to be most of my other packages (exaggeration, I know).
I really don't know where to go from here, so any guidance would be greatly appreciated.
Update:
I had to reinstall the python-tk package, and 2.6 is able to import it. Now I just need to figure out how to remove 2.4 for the sake of not screwing something up later on.
Here are a few commands which could help you diagnose your problem.
First, try to run the python command with the version number appended. Since
Synaptic says you have 2.6.6 installed you should be able to run python2.6 to
get that version:
(type 'python' and hit TAB to see possible completions)
% python<tab>
python
python2.6
python3.1
If you still can't get TK to run, find where the _tkinter.so module lives on
your system. It may be somewhere the 2.6.6 interpreter can't find it. Here's the location as installed by python-tk package on Ubuntu Lucid:
% find /usr -name '_tkinter*'
/usr/lib/python2.6/lib-dynload/_tkinter.so
Just an update for those who land on this page, regarding Python 3+ (like I have). To run tkinter on a Debian-based Linux (Ubuntu), python3 is needed, as well as python3-tk (it's not in the library list):
sudo apt-get install python3
sudo apt-get install python3-tk
Also, the script needs to have this as the first line:
#! /usr/bin/python3
At least that is how I solved the problem.
Related
This is probably a really dumb question but I am stuck and wasting too much time on this so I would SO appreciate any help.
I am using a RHEL 7 box and installed Apache Zeppelin on it. Everything works except for the life of me I can't import Python packages such as Pandas.
I realized I didn't have PIP so I installed it with these steps: https://pip.pypa.io/en/stable/installing/ (notice I had to use the "--user" argument for the command "python get-pip.py").
Finally, I did "pip install pandas --user" which worked perfectly. I then go into my Zeppelin notebook and I cannot import pandas, even after restarting the Python interpreter.
I did some research and I think the problem is that "which python" and "which pip" are installed in different directories as the former results in "/usr/bin/python" while the latter in "~/.local/bin/pip".
So I suspect the packages installed with pip are basically getting loaded into a different version of python? If it helps, when I do "whereis python" I get 5 different results such as "/usr/bin/python" and "/usr/bin/python2.7" etc.
First thing to understand is: Python packages aren't installed globally, every installed Python has its own set of packages. BTW, pip being a Python package with a script is also not global. If you have a few different pythons you need different pips for them. I don't know Apache Zeppelin so I cannot guess if it uses the system Python (/usr/bin/python) or has its own Python; in the latter case you need to install pip specifically for Zeppelin so its pip install packages available for Zeppelin.
To investigate to what Python pip installs packages you need to find out under what python it runs. Start with shebang:
head -1 `which pip`
The command will prints something like ~/.local/bin/python. If it's not the version of Python you need to install packages for you need to install a different pip using that Python.
The most complex case would be if the shebang is PATH-dependent, something like #!/usr/bin/env python. In that case pip runs Python that you can find with which python.
PS. AFAIK the simplest way to install pip at RedHat is dnf install python-pip.
phd's answer was very helpful but I found that it was just a matter of using the root account to install the python packages. Then my Zeppelin was able to see any packages.
I am trying to install wxPython from src as I need the exact version 3.0.2.0 on Ubuntu. (So, I cannot follow the suggesion in the related question) I downloaded the source and did ./configure, make and make install. It seems to have ended without errors with the following message.
The installation of wxWidgets is finished. On certain platforms
(e.g. Linux) you'll now have to run ldconfig if you installed a
shared library and also modify the LD_LIBRARY_PATH (or equivalent)
environment variable. wxWidgets comes with no guarantees and
doesn't claim to be suitable for any purpose.
I confirmed my installation is not working by doing import wx & wx.version(). What needs to be done to complete the installation? Where should I set the LD_LIBRARY_PATH to?
Doing ./configure, make and make install only builds and installs wxWidgets. You also need to build wxPython using the build-wxpython.py script, which by default will also do the wxWidgets portion of the build for you, using known good configure flags. See wxPython/docs/BUILD.txt in the source tarball.
Try to check if wx is in sys.pah.
You can do it with this code
import sys
print sys.path
In output must be something like that /usr/lib/python2.7/dist-packages/wx
If not, adding path to wx folder to system path should solve your problem.
gtk3 should be install first
$sudo apt-get libgtk-3-dev
If you are facing problem to install wxpython on Python3 please use this command to install wxpython
$ pip install -U -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-16.04 wxPython
By this command you can install latest wxPython4 version.
If you are using Windows or macOS
$ pip install -U wxpython
Older Version you can get from this link
https://sourceforge.net/projects/wxpython/files/wxPython/
I have installed scipy and numpy, and they are being used with my current, desired version of python 2.7.6 (I am running on OSX Mavericks and had to upgrade.) However, when I pip installed matplotlib, by default it referenced my previous python version, 2.7.5, thus making it troublesome to use (obviously.)
How do I change which version of python matplotlib uses so I can import and use the library?
Thanks.
The way I would solve this problem is like this, firstly one would need to go into your 2.7.6 directory, and under the Scripts folder you will find the pip executable. My suggestion is (because its difficult to debug this kind of people without having all the details) is this:
./pip install matplotlib
And see if this succeeds, otherwise, I suggest using pyenv to manage your python installations.
I suggest you use Macports for installing additional Python versions on OS X. Once Macports is installed, it's fairly easy to install Python 2.7.6. All you'd have to do is:
sudo port install python27
Now, you should be able to get all the libraries you need just as easily, using, too, Macports.
sudo port install py27-numpy
sudo port install py27-scipy
sudo port install py27-matplotlib
Macports should solve all the dependencies and, of course, link the packages to their correct Python versions, avoiding you a lot of headaches.
For a step by step guide on how to set up a nice, functional Python environment, visit: http://jakevdp.github.io/blog/2013/02/02/setting-up-a-mac-for-python-development/
I am running Ubuntu 10.10, and I installed Python 3.2 today. The system is already running Python 2.6.
I typed idle3.2 in the terminal and it gave me:
IDLE can't import Tkinter. Your Python may not be configured for Tk.
So I searched on Stack Overflow (and in some other places) for a solution, I installed python-tk, I rechecked that I have tclsh on the system, but I still can't manage to open idle3.2.
Any input would be appreciated.
On OSX, this can be resolved with macports by installing the python tkinter package for your python version. In my case, with python 2.7, I ran on the terminal:
sudo port install py27-tkinter
change the "27" to your python version number.
On Ubuntu:
sudo apt-get install idle
Choose one from
idle
idle3
idle-python2.6
idle-python2.7
idle-python3.1
idle-python3.2
for your python version.
The problem is caused by the version between python and idle not matching.
U can check your python version by typing : python
Then sudo aptget install the right idle version same with your python version
I ran into the same error message when installing python3.4 on Fedora 20. The problem was that tk-devel was not installed during the python configure/make. The explicit steps to do this correctly are
download and extract python3.4 from python.org https://www.python.org/downloads/
Find and install the right tkinter and tk-devel:
yum search tkinter
yum install python3-tkinter-3.3.2-17.fc20.x86_64
yum search tk-devel
yum install tk-devel.x86_64
AFTER these are onboard, cd into the python3.4 package directory and run the configure; make, make install process.
I spent too much time resolving this issue. Hopefully this post will help may others to a quick resolution.
PS stackoverflow is awesome. If google brought you to this article, spend some time and surf around the site.
If you installed python-tk and the system is running python 2.6 then it is most likely that you installed Tkinter for python 2.6. Try installing python3-tk.
you need to install tk or tk-dev packages for ubuntu.
On my arch linux system I had the same problem easily solved by typing
yaourt tkinter
and installing the first package community/python-pmw 2.0.1-2 [installed]
Type "idle-python2.6" in the terminal..it worked for me
I am trying to install the pycairo (Python bindings for the cairo graphics library) under OSX.
I started with
easy_install pycairo
and got:
Requested 'cairo >= 1.8.8' but version of cairo is 1.0.4
error: Setup script exited with Error: cairo >= 1.8.8 not found
So I went to cairo's site and downloaded the latest package (1.8.8) of cairo, and also the latest package of something called pixman (both source packages -- couldn't find osx binaries)
unzipped both, each in own directory.
for pixman, the regular ./configure ; make ; sudo make install worked just find
for cairo, ./configure seemed to work, but make failed with:
In file included from cairo-analysis-surface.c:37:
cairoint.h:71:20: error: pixman.h: No such file or directory
What am I doing wrong?
And why do I have to struggle so much to get a software library to work on an os that "just works"? Why isn't darwin more like linux?
If you already have homebrew, these two commands should be helpful:
$ brew install cairo --use-clang
$ brew install py2cairo
For a non-Homebrew installed Python, set the PYTHONPATH to find pycairo. You can set your PYTHONPATH in your .bashrc/.profile/.whatever to the following:
PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH.
I personally didn't need to use this last part but it might help you.
It appears you are mixing various install options here. The MacPorts package system port install command should automatically pull in all the dependencies needed for a particular package so the trick is to start with the right top-level project. For python packages, MacPorts has a general convention currently: packages that start with py- are for python 2.4, those with py25- are for 2.5, and py26- for 2.6. There are currently py-cairo, py25-cairo, and py26-cairo packages available in MacPorts.
By choosing py-cairo you picked the python2.4 version and you'll probably find that MacPorts built and installed a python2.4 for you (linked at /opt/local/bin/python2.4) and, if you launch it, you'll probably find that you can import cairo there. Now that may be OK for your needs but Python 2.4 is quite old and no longer supported so, if you're just starting, it might be better to start with Python 2.6, one of the two current versions of Python. To do so, all you should need to do is:
sudo port install py26-cairo
That should bring in any missing dependencies, mainly the MacPorts python2.6, which you can run from /opt/local/bin/python2.6. You may want to change your $PATH in your shell startup script, probably .bash_profile, to put /opt/local/bin early on the search path.
Because installing Cairo and its python bindings seems to be fairly complex, it should be easier and better to stick to using a complete MacPorts solution for this. That does mean you've needlessly (and harmlessly) installed a couple of Python instances that you won't need. But if you do want to clean things up a bit, you can easily remove the MacPorts python24 with:
sudo port uninstall py-cairo python24
Completely removing the python.org installed python is more complicated. I've explained the process here. But there's no pressing need to remove either as long as you keep your paths straight.
Ok. I solved it. Putting solution here for future reference, it might help someone.
Basically, the whole ports/fink system is a bit messed up, and osx doesn't really play nice with the linux-y world.
So, the steps I needed to install pycairo on OSX were:
download the latest source versions of pixman, cairo, pycairo
extract everything. Then:
cd PIXMAN_DIR ; ./configure ; make ; sudo make install
cd CAIRO_DIR ; cp PIXMAN_DIR/pixman/*.h . ; ./configure ; make ; sudo make install
cd PYCAYRO_DIR; locate cairo.pc
hopefully, several locations are returned. choose the most likely one (one with newest cairo). For me it was "/opt/local/lib/pkgconfig/cairo.pc" and do:
export PKG_CONFIG_PATH=/opt/local/lib/pkgconfig/
after this, still in PYCAIRO_DIR, do:
python setup.py install
This should do it...
The port command installs the library for the darwinports python installation, which is different to the framework build (so steps 2 and 3 shouldn't work). Try sudo easy_install pycairo instead (although your step 4 should be equivalent to this).
Look at which python too, to check that you are in fact running the python you think you are.
On Mac OS you can have multiple Python versions installed. You can have even more if you decide to install Python via Fink or MacPorts. When you compile libraries from the source, you should make sure they point to the correct installation.
I currently have Python 2.5.1 and Python 2.6.4 installed on my machine, which I can call via python2.5 and python respectively. They live in two different folders:
/System/Library/Frameworks/Python.framework/Versions/2.5and /Library/Frameworks/Python.framework/Versions/2.6
I was running into a similar problem when compiling pycairo 1.8.8 from the tarball. The INSTALL file in this case is your friend, as it contains the correct instructions to avoid potential version conflicts. You basically need to specify the correct prefix so that the package will be installed in the correct folder.
$ python -c "import sys; print sys.prefix"
# make a note of the python prefix
$ ./configure --prefix=[python_prefix]
$ make
$ make install # may require superuser access
Running these instructions with python2.5 and python you will be able to correctly install pycairo for both versions (or for any version installed via MacPorts / Fink).
Step 1: Run this from terminal ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
Step 2: brew install cairo
Step 3: pip install pycairo