Python installation error using pyenv Tkinter not found MAC - python

I had to uninstall and reinstall python for other reasons.
Right now I downloaded python 3.8.2 through pyenv but running:
import tkinter
The error I get is:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/cagava/.pyenv/versions/3.8.2/lib/python3.8/tkinter/__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
why is that so? Am I missing some modules in python installation?
Note that I am working on a Mac
I've tried the solution proposed on the issue (Python not configured for Tk) and others suggesting the same method but it didn't solve my problem

Struggling with this myself. For all the talk about the "annual ritual" to include tkinter with Python, it sure isn't well integrated, especially when using pyenv.
I'm about to take the plunge one site suggested: removing pyenv completely, then installing tcl-tk, then compiling a number of post-tcl-tk dependencies that come up after the tcl-tk install, then reinstalling pyenv (which should, supposedly, then add tkinter support - even though tkinter was installed on the default system python of 2.7.16, then reinstalling the versions of Python I've already installed (3.7 and 3.8 and which seem to work for everything but tkinter). Like I said - not well integrated. Were it not for the many comments about how well tkinter has been expanded and maintained I'd be tempted to (and actually, was tempted to) try something else.
Linux Ubuntu and PopOS (Ubuntu derivative) both display the same problem, on two different machines. I'll give the above a try and report back on the fireworks.

Related

Really messed up my Linux Ubuntu system python

Example: I was trying to update my system today and I got this error:
wli#ubuntu:~$ update-manager
Traceback (most recent call last):
File "/usr/bin/update-manager", line 28, in <module>
from gi.repository import Gtk
File "/usr/lib/python3/dist-packages/gi/__init__.py", line 36, in <module>
from ._gi import _gobject
ModuleNotFoundError: No module named 'gi._gi'
Not sure what to do? Ive tried every common fix found in forums online, reinstalling and uninstalling python, everything. The only thing I can think of that may have caused this is that I tried to change my system's python version through a series of convoluted commands in order to force Atom to use python3. Any ideas for how I can fix this? I'd really like to be able to install things on my laptop; I can't even reinstall Ubuntu because that requires actually being able to use Python.
I even made my system point to 2.7.6 using update-alternatives but it still doesn't work.
For reference, the system Python version is now 2.7.6 and I run 14.04.

ValueError: Namespace Gtk not available after installing gobject

Edited for posterity: I got it to work. In my case, I had to use the --user option in pip. pip uninstalled pympress and then
python3 -m pip install --user pympress
OP continues below:
I'm trying to install Pympress, a LaTeX Beamer slideshow viewer on MacOS High Sierra. I've been wrestling with this install for a couple days now with various issues. I think I'm getting close, with everything finally settled on my Python 3.7 build. However, I'm hung up on the Gtk dependency.
Having installed all the dependencies (as far as I can tell, including things that I think aren't well-described on that Github page), I go to run the program with
pympress my_slides.pdf
and get the ValueError in the traceback below:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/bin/pympress", line 7, in <module>
from pympress.__main__ import main
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-
packages/pympress/__main__.py", line 41, in <module>
from pympress import util
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pympress/util.py", line 36, in <module>
gi.require_version('Gtk', '3.0')
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/gi/__init__.py", line 129, in require_version
raise ValueError('Namespace %s not available' % namespace)
ValueError: Namespace Gtk not available
It just doesn't seem to have installed the gtk3 namespace in the proper place (and I don't know where it is at the moment, if at all), and I'm at a loss as to how to do so manually, if possible. The closest I've heard is installing gir1.2-gtk-3.0, but as far as I can tell that's a Linux need only, and neither brew or pip find it (same issue as this post).
Following the minimum working program on the PyGObject site site (another low-level dependency), I have the same namespace error. I've installed using their instructions as well, written their hello.py file and it doesn't run, with the same issue.
Have I missed a dependency somewhere? I've both followed the Pympress dependency install directions to the letter, as well as restarting and installing everything various ways independently using brew, which itself doesn't show any broken links.
Edit: it seems that manually compiling gtk and its dependencies, not going through brew, solved this namespace problem. That said, the package is also dependent on Poppler, which is now giving me the same error, just farther along in the code. Manually compiling this time hasn't seemed to work. I'll leave this up for posterity (and in case anyone has thoughts), but my current "workaround" is just going to be booting into Windows for the program, as binary installers are available.

No module named 'tensorflow' error showing up in Windows 10 Python 3.6

I installed Tensorflow using the instructions on its website https://www.tensorflow.org/install/pip. I used the virtual environment option, but didn't use Anaconda.
Everything went smoothly until I tried to import tensorflow in python. I did
import tensorflow as tf
in my Python file and in return I get
Traceback (most recent call last):
File "...", line 1, in <module>
import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'
What's up with this? How can I fix it? I'm using Python 3.6 on a Windows 10 machine. All other answers to this I could find involved Anaconda which I didn't use.
Thanks in advance!
I recommend you start using Anaconda. It just makes life so much easier (especially when handling different Versions of TensorFlow)
Make sure that you are in the Environment you‘ve installed it. Note that you need to activate it first (as shown on the Installation tutorial).
Another thing you can try is installing it with pip3. Although this didn‘t always work for me (it can lead to trouble when having python 3.7 installed)
Lastly you could lookup which python is linked in the PATH and verify that the tensorflof packages are actually there.

Which package to install based only on import line

I am very new to Python, and I am attempting to reproduce an example (not necessary to answer the question). If all I have is import threading from within the code I assumed I could just run pip install threading however the module is not found. When I searched for a different package name in the Python package manager I came across hundreds. Why doesn't the pip command work, and how do I know which package to install?
My exact error
:\Users\king\Desktop\_REPOS\misc\stock_analysis\forex\python\pythonv2>python trading.py
Traceback (most recent call last):
File "trading.py", line 1, in <module>
import Queue #pip install queuelib
ImportError: No module named 'Queue'
Version info
Python 3.5 32bit (64 bit OS)
The first hit on google (search: python threading) actually gave me:
https://docs.python.org/2/library/threading.html (the URL itself already indicate it)
This means it's a library module so it should be already available to you without extra installs.
In case your Python is limited in a way and doesn't have it by default, please update your question with your Python version and way it was installed.
For future reference, you were mostly doing the right thing, a lot of modules have the same name as their import statements, but otherwise, in almost all case, a simple Google search will suffice.

ImportError: No module named twisted.persisted.styles

From IDLE, I tried to run a script with a newly installed scrapy 1.0.3.
I'm using a script from a friend whom it worked for (but on Windows, I'm on a Mac).
From the import of scrapy on the first line, I get this error when running the program:
ImportError: No module named twisted.persisted.styles
The whole script, if it's helpful, points to this:
Traceback (most recent call last):
File "/Users/eliasfong/tutorial/tutorial/spiders/medspider.py", line 1, in <module>
import scrapy
File "/Library/Python/2.7/site-packages/scrapy/__init__.py", line 27, in <module>
from . import _monkeypatches
File "/Library/Python/2.7/site-packages/scrapy/_monkeypatches.py", line 20, in <module>
import twisted.persisted.styles # NOQA
ImportError: No module named twisted.persisted.styles
Any suggestions on how to tackle this problem?
Just try to force the update of twisted :
pip install twisted --upgrade
That works for me with python3.4 and Scrapy==1.1.0rc1
Either twisted is installed on your mac (I highly doubt it since it's not a standard library) and for whatever reason the IDE (i'm assuming that's what you mean since you typed "idle") or the terminal you are in doesn't have your updated environment variables, meaning it doesn't understand where your default python libraries are (again I highly doubt it), or you simple do not have twisted installed on your mac. If it's not installed you have a couple of options:
The easiest way to install a python package is through pip.
If that not an option you can try homebrew which is another package manager for macs. It offers an easy way to install packages correctly.
If that still is not an option for you or you simply don't want to attempt that you can download twisted directly from here (the .bz2 since you're on a mac), click on it and it should unzip it for you. Then just run setup.py and it should install it in the correct location on your mac.
If that still doesn't work and you have decent knowledge of unix. Use the "locate" command on the terminal and find out where your dist-packages directory is and put the source for twisted in there directly and then attempt to import twisted in your IDE or in the python interpreter to verify that it is installed.
note: If you're still having problems after it is installed trying restarting your IDE or messing with some setting to make sure your IDE has the right environment and python path. Hope that helps!
It could be related to having installed Python without bzip2. I had the same error and this helped me, see the accepted answer here:
Installing Twisted through pip broken on one server
Had this exact thing on FreeBSD. Solution (as root/sudo):
chmod -R go+rX /usr/local/lib/python2.7/site-packages
Some directory permissions weren't set up right on install.

Categories