Really messed up my Linux Ubuntu system python - 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.

Related

How do I fix python 3.8.5. error "ImportError: cannot import name 'open_code' from 'io' (unknown location)"

I'm a complete novice as far as python is concerned, but need to install it for PlatformIO. I installed python-3.8.5-amd64.exe on Windows 10 and installed PlatformIO in VSCode. But when I try to do a build I get:
Fatal Python error: init_sys_streams: can't initialize sys standard streams
Traceback (most recent call last):
File "C:\Program Files\Python38\lib\io.py", line 54, in <module>
ImportError: cannot import name 'open_code' from 'io' (unknown location)
Since io.py is installed as part of the python installation, I assume the 'open_code' symbol should be installed. Running the Repair option from python-3.8.5-amd64.exe and rebooting claims everything's fine, but it still fails.
Can someone explain, in simple terms, what I need to do to fix this?
Note: there's an answer here which indicates it's due to there having been 2 versions of python installed and that something's pointing at the wrong verison, but it doesn't explain how to fix it in any way that I understand (as well as being for a Linux installation).
Thanks.
The solution was to delete the .platformio folder from my user folder. Obviously, PlatformIO was 'remembering' the previous python install and confusing things!
this happened to me when multiple versions of Python was installed , and the PATH environment variable had a python path whose version was different from what i was executing. Adjusted the path variable to demote the unused python version and promote the currently used version and it solved the problem.thanks!

Python installation error using pyenv Tkinter not found MAC

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.

Using a Python Package Outside of Anaconda

I wish to run a package, openquake; however, it was installed separately from Anaconda, which I am using to run python.
[centos modules]$ which python
~/anaconda2/bin/python
I have set openquake up and I believe it's installed correctly, however, when I try to run my script, I receive the following error:
[centos maxdist]$ python ../script.py
Traceback (most recent call last):
File "script.py", line 12, in <module>
from openquake.hazardlib.source import ComplexFaultSource
ImportError: No module named openquake.hazardlib.source
I was wondering if I need to add a line to my script for it to find the openquake module for it to run successfully? In general, what's the best way to run a python package that is installed outside of the main Anaconda python instance? I am trying to avoid having to re-install openquake for Anaconda, as I was having a little bit of difficulty with that work-around.
Thank you.
If both environments, anaconda and default python that you installed the library for have the same python version, then
import sys
sys.path.append(r'/path/to/package')
from openquake.hazardlib.source import ComplexFaultSource
Check if this works. If the package is compiled for different version, then there will be an error. Also, I would suggest you to use one environment and avoid doing this for the sake of simplicity.

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.

Install Panda3d to run with python

I am running Ubuntu 10.04, I have python installed and running fine. When I installed pand3d from the deb package from the site and tried to run an sample. Like it is describe in this page:
http://www.panda3d.org/manual/index.php/Installing_Panda3D_in_Linux
I got the error:
Traceback (most recent call last):
File "Tut-Asteroids.py", line 13, in
import direct.directbase.DirectStart
ImportError: No module named direct.directbase.DirectStart
In the same page as above there is a description to how to solve this error. But I don't understand what do I need to do.
Can any one tell-me what do I need to do?
Found the answer. I had two pythons installed. One in /usr/bin and the other in /usr/local/bin. Turn out I needed to use the /usr/bin version to run what I needed. Hope this helps other!

Categories