I just installed PyQt 5.7.0 on my google compute engine machine which running on a ubuntu 16.04:
However, when I wanted to run PyQt and import some module, it produce Segmentation fault (core dumped) error as shown:
Can I know how do I solve it? I have been searching an answer for this for hours and still can't find an answer. Will be greatly appreciated if anyone could help.
You can try (as explained in the comments) to compile PyQt5.7 yourself, using a different version of Python (3.4.3 and 3.4.4 worked for me, everything above 3.5 did not). Note that I also compiled Qt5.7 myself, but you can use the one provided by the installer. Here is a short, hopefully exhaustive, set of commands to setup a virtual environment:
Install dependencies using apt:
sudo apt-get install -y build-essential libgl1-mesa-dev libx11-dev libxext-dev libxfixes-dev libxi-dev libxrender-dev libxcb1-dev libx11-xcb-dev libxcb-glx0-dev libfontconfig1-dev libfreetype6-dev libglu1-mesa-dev libssl-dev libcups2-dev python3-pip git
Install Python 3.4.4:
cd ~/Downloads
wget https://www.python.org/ftp/python/3.4.4/Python-3.4.4.tar.xz
tar xf Python-3.4.4.tar.xz
cd Python-3.4.4
./configure
sudo make altinstall
Create the virtual environment:
sudo pip3 install virtualenv
virtualenv -p /usr/local/bin/python3.4 ~/python34
source ~/python34/bin/activate
Install Qt:
cd ~/Downloads
git clone git://code.qt.io/qt/qt5.git
cd ~/Downloads/qt5
git checkout 5.7
./init-repository
./configure -prefix ~/Qt/5.7/gcc_64 -opensource -nomake examples -nomake tests -release -confirm-license
make -j 5
make install
Install SIP:
cd ~/Downloads
wget http://downloads.sourceforge.net/project/pyqt/sip/sip-4.18.1/sip-4.18.1.tar.gz
tar xf sip-4.18.1.tar.gz
cd sip-4.18.1
python configure.py
make
sudo make install
Install PyQt:
cd ~/Downloads
wget http://downloads.sourceforge.net/project/pyqt/PyQt5/PyQt-5.7/PyQt5_gpl-5.7.tar.gz
tar xf PyQt5_gpl-5.7.tar.gz
cd PyQt5_gpl-5.7
python configure.py --qmake ~/Qt/5.7/gcc_64/bin/qmake --disable QtPositioning --no-qsci-api --no-designer-plugin --no-qml-plugin --confirm-license
make -j 5
sudo make install
Caveats:
I'm going to assume that you can't run any GUI programs right now in your vm.
I'm not that familiar with GCE platform and have not tried what I'm going to propose
Follow the steps at Your desktop on Google Cloud Platform to install a desktop GUI manager in the GCE vm (it will be X11-based for Linux OS), as well as vnc server.
Once you are vnc'd in to your vm using realvnc or tightvnc viewer, a GUI app will likely run. You may have to change the X11 DISPLAY variable -- eventhough the above link does not discuss this -- because AFAIR *nix systems use a separate desktop session for VNC than the one currently logged in.
I doubt it will run if there is no user logged on to the GCE vm.
If you installed PyQt5 with apt or apt-get, now do also
sudo pip3 install pyqt5
You cannot run a GUI program (PyQt) remotely, unless both machines use X11 protocol with properly set DISPLAY variables and xhost permissions. I doubt that Google compute engine is configurable to run in the X11 mode.
When you import PyQt5, it will also import PyQt5.QtCore because PyQt5.QtCore is part of PyQt5.
Related
I just upgraded python in ubuntu to python 3.10 to use the match/case statements, but now, my terminal won't open. Anywhere. I tired opening it on Visual Studio Code, but it says the path does not exist. Gnome terminal and terminator won't even give any feedback. I am using Ubuntu 20.04 with i3wm, my shell is zsh, and here are the commands i used (i modified them from this site and this site):
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.10
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.10 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.6 10
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python2.6 10
sudo update-alternatives --config python
sudo update-alternatives --config python3
For what I remember my previous python version was somewhere around 3.7.
If you prefer, here are the specs from above:
OS: Ubuntu 20.04
Shell: zsh (oh-my-zsh)
WM: i3
Terminal: gnome-terminal
Important: Please remember I do not have access to a terminal. I have still not tried recovery mode, but if you have a non-termianl based solution, it is preferred.
Just found a way to undo it. If you encounter the same problem, here is what I did:
Ctrl+Alt+Fn and a few F buttons (F1, F2, F3...) until I got to a tty menu.
I logged in as myself (not root), and ran sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1 to make the default python 2.8 with sudo update-alternatives --config python3 again. Then it worked properly.
Edited
New Answer
I found a better way to install your preferred python version. It's more stable and more secure than using ppa:deadsnakes/ppa repository.
Sure now this is not a direct answer to the problem you had anymore. But I am editing this answer here in hope to help you and anyone that may want to install python3.10 in a machine that does not come with it installed by default.
You can use asdf, which is a tool version manager. With it you may install any python version you want, independent of your OS. It is gonna be more verbose, but works perfectly well, without any conflict with some pre-installed python version.
To avoid problems when installing asdf and python, install the following packages:
sudo apt install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev
Then run:
sudo apt update && sudo apt upgrade
to make sure everything is up to date.
Installing asdf
To install asdf, first we clone from the repository and the branch of asdf version we want (Please note that the version specified in the end of the command may change. I just followed the documentation):
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.10.0
Now you only got to add a few lines to the end of your script configuration file. It may change according to your shell, but again, check the documentation for specific instructions (including zsh).
To find out what kind of terminal you're using, you can run:
echo $SHELL
If your're using bash then you can add the following to the end of your ~/.bashrc (yes, the dots are included):
. $HOME/.asdf/asdf.sh
. $HOME/.asdf/completions/asdf.bash
After that, you just have to restart your terminal.
Installing python3.10 (or any version you want)
Now with asdf installed, you should install a plugin to manage multiple python versions. To do that, just run the command:
asdf plugin-add python
To globally install python3.10.4 in your system, run:
asdf install python 3.10.4
And then:
asdf global python 3.10.4
Lastly, run:
asdf reshim
This last command is a somewhat refresh for asdf to work properly after globally installing libraries. Run it whenever you install something with asdf, just to be sure.
No need to worry about running this command after installing some package or module with pip though (well, at least I never had).
Credits to Kenzie Academy. Learned it there.
Old Answer
I ran exactly into the same problem. I found the answer here.
At first, I tried to simply open the gnome-terminal file without a terminal and change it, but it didn't work, because using a GUI I had no sudo permissions. So the workaround that worked for me and I expect that may work for you, was to open the file with VSCode and then used the VSCode integrated terminal to run the following command:
sudo nano /usr/bin/gnome-terminal
Of course you don't have to use nano, you could use vim or something else. Anyway, once there, you can change the first line of the file, which is a comment, from
#!/usr/bin/python3
to
#!/usr/bin/python3.8
Ubuntu 20.04 is well compatible with python3.8, so that's why I suggested you putting python3.8 there but you could surely test if some other version works.
This is not a way to go back to python3.8. You will still have the add-ons of python3.10.
I have a docker file that installs all the dependencies and creates an environment for the application, but there is one particular one that is giving me a hard time.
I am using this command to install tkinter in docker container
RUN apt-get install -y python3-tk
But this one gives a prompt to select for time zones and geography.
I am currently circumventing this by getting in the docker and install the same in container with
docker run -ti tag:latest /bin/sh
which isn't very neat, is there a way around this one, Either to do one of the following
Auto select the prompt (with something like expect and send)
Install tkinter without prompt maybe defaults.
Any suggestions that are not complete answers for similar problems are appreciated as well, we can also install it in a different way if possible without apt
I had the same problem, and I used this in my Dockerfile:
ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Europe/London
RUN apt-get install -y python3-tk
This is based on this answer: How to install tzdata on a ubuntu docker image?
I have the problem that when I run my code on a linux server I get:
ModuleNotFoundError: No module named '_sqlite3'
So after researching, I found out sqlite3 was supposed to have been installed when I installed python, however it didn't.
I think the problem comes from the way I installed python. Since I do not have sudo permissions, I installed python3.7 in a local directory using: This guide.
All solutions to this sqlite3 problem that I can find requires sudo commands.
Is there another way that I can install python3.7 together with sqlite3 in my local Linux directory without using any sudo commands?
I hope I have stated my question clearly and I would appreciate all the help I can get. Thank you!
While installing a python package in a Linux system without "sudo" privileges you can use
For Python 3
pip3 install --user pysqlite3
You can install any third party packages with the same method
pip3 install --user PACKAGE_NAME
The --user flag to pip install tells Pip to install packages in some specific directories within your home directory. For more information click here.
Hope it helps !
The solution is to first build sqlite3 into a user directory and then build python using that directory's libraries and include headers. In particular, #Ski has answered a similar question regarding python 2, which can be adopted to python 3:
$ mkdir -p ~/applications/src
$ cd ~/applications/src
$ # Download and build sqlite 3 (you might want to get a newer version)
$ wget http://www.sqlite.org/sqlite-autoconf-3070900.tar.gz
$ tar xvvf sqlite-autoconf-3070900.tar.gz
$ cd sqlite-autoconf-3070900
$ ./configure --prefix=~/applications
$ make
$ make install
$ # Now download and build python 2, same works for python 3
$ cd ~/applications/src
$ wget http://www.python.org/ftp/python/2.5.2/Python-2.5.2.tgz
$ tar xvvf Python-2.5.2.tgz
$ cd Python-2.5.2
$ ./configure --prefix=~/applications
$ make
$ make install
$ ~/applications/bin/python
Alternatively, if you already have to specify a different --prefix for some reason (this has happened to me with pyenv), use LDFLAGS and CPPFLAGS when configuring python build:
$ ./configure LDFLAGS=-L/home/user/applications/lib/ CPPFLAGS=-I/home/user/applications/include/
I have a headless Ubuntu 14.04 Server that I connect to remotely using SSH. I want to use matplotlib and have plots appear at the ssh client. For example, I would connect using:
ssh -X name#server.com
And then from a Python console, I want this to produce a plot in a window:
import matplotlib.pyplot as plt
plt.plot(range(10))
plt.show()
I have installed matplotlib in my virtualenv, and I ran sudo apt-get install python-gtk2, but the plot still doesn't appear. I assume I'm missing lots of packages. What is a fairly minimal set of X-related packages I could install to make this work? I do NOT want to install ubuntu-desktop.
I got it working on Ubuntu 14.04.1 Server, but it was painful! The tricky part is definitely virtualenv. I finally had luck using the Qt4 backend, which I was only able to install via the Ubuntu package and then had to symlink it into my virtualenv. So here's the step-by-step process...
First install the pre-reqs and hack PyQt4 into your virtualenv:
$ sudo apt-get install xauth x11-apps python-qt4
$ ln -s /usr/lib/python2.7/dist-packages/PyQt4 /path/to/myvenv/lib/python2.7/PyQt4
Now manually download and install SIP (http://www.riverbankcomputing.com/software/sip/intro) with your venv activated, as follows:
$ tar xzf sip-4.16.4.tar.gz
$ cd sip-4.16.4
$ python configure.py
$ make
$ sudo make install
Next, download matplotlib source tarball and modify the setup configuration to force it to install Qt4 backend:
$ tar xzf matplotlib-1.4.2.tar.gz
$ cp matplotlib-1.4.2/setup.cfg.template matplotlib-1.4.2/setup.cfg
Now edit setup.cfg near line 68 to read:
qt4agg = True
Matplotlib will now install cleanly in your venv:
$ pip install -e matplotlib-1.4.2/
Now you can SSH using the -X flag and plots will load remotely!
What's the best way to get the latest SHOGUN / Python modular interface (http://www.shogun-toolbox.org) installed on 12.04? I tried from source without much luck (happy to post errors); Is it possible to install the Trusty Tahr package on 12.04? https://launchpad.net/ubuntu/+source/shogun/3.1.1-1
(I am the debian maintainer of this package).
You could try to
apt-get -b source shogun
but it will give you only the core libshogun library at this very moment. There is a python package on the way (in debian) but not yet accepted and not yet in ubuntu.
https://ftp-master.debian.org/new/python-shogun_3.1.1-1.html
So you are really best of installing from source. Shogun has buildbots running on ubuntu creating a python package. So you can just copy the settings from there:
https://travis-ci.org/shogun-toolbox/shogun/jobs/18605663
Following this posts here and this instruction i did the following that worked for me to install shogun directly into my conda env. Its not the most elegant way but worked out so far.
! Take care to have swig: ie. installed apt-get install swig
! I used anaconda and the shogun python infterface - so my cmake prefix was /home/user/anaconda/
You need cmake to build shogun:
SET UP CMAKE FIRST (skip if you have cmake > 3.1)
cd /path to your installation directory
workdir=$(pwd) #i.e. your home
Download and install cmake into your home:
wget http://www.cmake.org/files/v3.1/cmake-3.1.3.tar.gz
tar xzf cmake-3.1.3.tar.gz
cd cmake-3.1.3
cmake_dir=$workdir/cmake 5 ./configure --prefix=$cmake_dir
make -j 2
make install
Export cmake to your PATH so you can use it for shogun: export
PATH=$cmake_dir/bin/:$PATH
Download and install shogun into anaconda env
wget ftp://shogun-toolbox.org/shogun/releases/3.1/sources/shogun-3.1.1.tar.bz2
tar jxf shogun-3.1.1.tar.bz2 3 cd shogun-3.1.1/
mkdir build
cd build
cmake -DPythonStatic=ON -DPythonModular=ON -DCMAKE_INSTALL_PREFIX=/home/myusername/anaconda/envs/p27/ ..
make -j2 all #four processes takes a while
make install