error importing QtGui from Pyside - python

I just downloaded and installed PySide and I am getting this error when I try to import QtGui from PySide
$ python -c "from PySide import QtGui"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: dlopen(/Library/Python/2.7/site-packages/PySide/QtGui.so, 2): Symbol not found: __ZN7QLayout11adoptLayoutEPS_
Referenced from: /Library/Python/2.7/site-packages/PySide/QtGui.so
Expected in: /Library/Frameworks/QtGui.framework/Versions/4/QtGui
in /Library/Python/2.7/site-packages/PySide/QtGui.so
any help would be greatly appreciated.

Just installed PySide from pip yesterday.
Checked "python -c "from PySide import QtGui" everything importing fine.
Firs check if you have QtGui.so in "/Library/Python/2.7/site-packages/PySide/" directory, cause a have.
Some month ago trying to install PyQt from sources got problem with compilation: everything looks fine, but some modules (including QtGui) was absent (can't remember but problem was in some config file).

Try remove the: __ZN7QLayout11adoptLayoutEPS_ from /Library/Python/2.7/site-packages/PySide/QtCore.so file.
You code is correct: python -c "from PySide import QtGui"
but the problem is on your os system, download PySide from official website: https://pypi.python.org/packages/f1/32/63872fdc1d9e0de5aa0b05b9d1a17d868851c619cdc6998dd9d853556f1b/PySide-1.2.1.tar.gz#md5=b551d6ff68685013b59e478571f775bf
If you are using Windows, run cmd and type this command:
cd <type here the python path>
example: cd C:\Python27
and type:
python <here the path of the extracted and download pyside file>\setup.py install
example: python C:\users\someuser\pysyde_extractedfiles\setup.py install
If you are usinc Mac OS X run the terminal and type:
cd /<you_python_install_dir>
python /<your_extracted_pyside_files_path/setup.py install>
example: cd /opt/python27 && python /tmp/pyside_extracted/setup.py install
If you are using Linux (Ubuntu, Debian, ArchLinux)
wget <here_the_pyside_download_url>
cd /home/<you_username>/<you_extracted_pyside_folder>
python setup.py install
If you use python3 then type:
python3 setup.py install
I hope this help you!

Related

Python3 import error: No module named 'rpm'

On a CentOS 7 I have installed python3 with the following command:
yum install -y python3
However, when I call import rpm, I get this error:
File "\<stdin>", line 1, in \<module>
ModuleNotFoundError: No module named 'rpm'
So how do I import the python3 rpm module?
Running rpm --version returns
RPM version 4.11.3
Accessing python (2.7.5) and running the import command works. So I could call a python2 script from python 3, as described here but this just feels wrong.
There are similar questions to this but they all relate to the rpm module being unavailable from Python2 and I don't have that problem. None deal with making the rpm module available in Python3.
Did you install the rpm python package for the python3 distribution?
pip3 install rpm-py-installer
Per the homepage of RPM this seems to be a required step.

Python script compiled to .exe giving error: No module named yaml

I can run the code below in Pycharm without issues, but when I create an exe using pyinstaller, I get the following error when I run the executable -
**Traceback (most recent call last):
File "openfile.py", line 1, in <module>
ImportError: No module named yaml
[1296] Failed to execute script openfile**
import yaml
from sys import exit
cfg = yaml.safe_load(open("Config.yml"))
exit()
Note that I'm using Windows 10.
pip install pyyaml will solve this problem
or use virtualenv
pip install virtualenv -p python3 #or python2
virtualenv venv
venv/Scripts/activate
pip install pyyaml

ImportError: No module named sip (python2.7 PyQt4)

I'm currently using Ubuntu 18.04 LTS.
I'm trying to install a program that need PyQt4 and QtWebKit, so a manual installation is necessary as QtWebKit have been excluded from PyQt4.
I downloaded sip 4.19.12 (with 4.19.14 installation of PyQt4 fails) and PyQt4 4.12.13
I ran a virtualenv, made sure it was working as intended and tried installing sip, which works:
$ python configure.py
$ make
$ make install
Then I proceed with the same with PyQt4, with no errors.
When I try to run my program .py, it gives the following error:
$ python RNAEditor.py
Traceback (most recent call last):
File "RNAEditor.py", line 9, in <module>
from Helper import Helper, Parameters
File "/home/bioinfo/Documentos/Ferramentas_RNAEditor/RNAEDITOR_ch/Helper.py", line 13, in <module>
from PyQt4 import QtCore
ImportError: No module named sip
$ sudo python RNAEditor.py
Traceback (most recent call last):
File "RNAEditor.py", line 9, in <module>
from Helper import Helper, Parameters
File "/home/bioinfo/Documentos/Ferramentas_RNAEditor/RNAEDITOR_ch/Helper.py", line 13, in <module>
from PyQt4 import QtCore
ImportError: No module named PyQt4
I'm sure that my virtual env does have sip and PyQt4, as importing both within virtualenv/python gives no error too.
$ python
>>> import PyQt4
>>> import sip
>>> from PyQt4 import QtCore
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named sip
Any ideas on how to set PyQt4 and sip with a manual installation, or why it is not working as intended?
PyQt started from version 4.12.2 needs private sip module called PyQt4.sip (see file NEWS in PyQt 4 source folder)
So you should configure sip using this command:
python configure.py --sip-module PyQt4.sip
After sip is built, you should copy file sip.pyd to PyQt4 python directory - by default it is c:\python27\Lib\site-packages\PyQt4
I got it to work with specific SIP and PyQt4 versions and running inside a virtualenv. I have no idea what happens, but it seems that in Ubuntu 18.04 something happens with the last versions of PyQt4 and SIP and they do not work as intented, but they do work in Ubuntu 16.04 (tested).
The code that worked in Ubuntu 18.04 is:
PYQT4 4.12.1 and sip 4.19.12
sudo apt-get install python-pip python2.7-dev libxext-dev python-qt4 qt4-dev-tools build-essential
pip install virtualenv
virtualenv PROJECTNAME
source PROJECTNAME/bin/activate
cd SIP_SOURCE_DIRECTORY
python configure.py
make
make install
cd PYQT4_SOURCE_DIRECTORY
python configure.py
make
make install
Then you have your virtualenv where QtWebKit is supported, which is important for many applications

Running fabric script throws ImportError: No module named fabric.main

I am on Redhat, and when I run any fabric scripts I see the following error:
Traceback (most recent call last): File "/usr/bin/fab", line 8, in
from fabric.main import main ImportError: No module named fabric.main
The file /usr/bin/fab is configured to use python 2.7 (/usr/local/bin/python):
#!/usr/local/bin/python
# -*- coding: utf-8 -*- import re import sys
from fabric.main import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
The result is the same even if I just call fab.
Not sure what else I should be configuring. I have not set up a virtualenv for fab. If I must, I will do so.
I installed python 2.7, and then I installed fab as follows:
wget https://bootstrap.pypa.io/get-pip.py
sudo /usr/local/bin/python get-pip.py
sudo /usr/local/bin/pip install fab
I ended up doing the following:
Install Python 2.7 in a virtualenv (~/virtualenvs/py2.7) by following the top-rated answer from Is it possible to install another version of Python to Virtualenv? by DTing
Install pip in ~/virtualenvs/py2.7/bin/:
wget https://bootstrap.pypa.io/get-pip.py
sudo ~/virtualenvs/py2.7/bin/python2.7 get-pip.py
Install fab in ~/virtualenvs/py2.7/bin:
sudo ~/virtualenvs/py2.7/bin/pip install fab
For some reason, I still did not have the fab file under ~/virtualenvs/py2.7/bin, so I just copied the original /usr/bin/fab that was giving me issues to ~/virtualenvs/py2.7/bin/ and edited it to point to the virtualenv python2.7 (~/virtualenvs/py2.7/bin/python2.7)
Running ~/virtualenvs/py2.7/bin/fab worked, and gave me the following (welcome) error:
Fatal error: Couldn't find any fabfiles!
Remember that -f can be used to specify fabfile path, and use -h for
help.
Aborting.
I am content for now -- since fab seems to work. But if anyone has ideas why the actual fab file was not created in the ~/virtualenvs/py2.7/bin/ directory, I am all ears. Thank you!

ImportError: No module named distutils

Attempt to install psutils resulted a big headache...
$ python -V
Python 2.4.2
$ cat /etc/SuSE-release
SUSE Linux Enterprise Server 10 (x86_64)
VERSION = 10
PATCHLEVEL = 4
$ cd psutil-2.1.1/
$ python setup.py install
Traceback (most recent call last):
File "setup.py", line 17, in ?
from distutils.core import setup, Extension
ImportError: No module named distutils.core
Next - I try to install setuptools to use easy_install:
$ which easy_install
which: no easy_install
$ cd ../setuptools-1.4/
$ python setup.py install
Traceback (most recent call last):
File "setup.py", line 12, in ?
from distutils.util import convert_path
ImportError: No module named distutils.util
Trying install distutils from ez_setup.py:
$ python ez_setup.py
Traceback (most recent call last):
File "ez_setup.py", line 278, in ?
main(sys.argv[1:])
File "ez_setup.py", line 210, in main
egg = download_setuptools(version, delay=0)
File "ez_setup.py", line 139, in download_setuptools
from distutils import log
ImportError: No module named distutils
So - how can I install it?
P.S. No, I haven't root on this machine and can't use package manager.
you need to run this (if Error happens on python3) ==> sudo apt-get install python3-distutils --reinstall
you need to run this (if Error happens on python2) ==> sudo apt-get install python2-distutils --reinstall
I have an answer here but I will copy it here
AskUbuntu answer:
Debian has decided that distutils is not a core python package, so it is not included in the last versions of debian and debian-based OSes. You should be able to do sudo apt install python3-distutils and it should work.
However, it did not work for me. I use Parrot OS, which is, as Ubuntu, Debian based. I upgraded my system and pip stopped working for python3.7, and I also got the error ModuleNotFoundError: No module named 'distutils.util'
I tried a lot of stuff to fix it and to reinstall distutils, and I found out by pure luck, that pip3, for python3.8 did work. I then tried python3.7 -m pip3 -V, got /usr/bin/python3.7: No module named pip3 so I decided to have a look in the /usr/lib files.
I looked at /usr/lib/python3/dist-packages and everything looked fine. Then I looked at /usr/lib/python3.7 and saw the folder distutil.
I opened it, and saw the __pycache__, the __init__.py file and a version.py file. I had no idea how many files should be in there, or what the code should be, but I knew that those two files were either wrong or missing another file.
Then I had a look at what was inside /usr/lib/python3.8/distutil and it was totally different. I found the following files:
command Folder
__pycache__ Folder
archive_util.py Python script
bcppcompiler.py Python script
cmd.py Python script
config.py Python script
core.py Python script
cygwinccompiler.py Python script
debug.py Python script
dep_util.py Python script
errors.py Python script
extension.py Python script
fancy_getopt.py Python script
filelist.py Python script
file_util.py Python script
__init__.py Python script
log.py Python script
msvc9compiler.py Python script
_msvccompiler.py Python script
msvccompiler.py Python script
README Plain text file
spawn.py Python script
sysconfig.py Python script
text_file.py Python script
unixccompiler.py Python script
util.py Python script
version.py Python script
versionpredicate.py Python script
This was a lot more promising, and since pip3 did work, I assumed that this distutils worked too, and I tried to copy it to the python3.7 folder by running this command:
sudo cp -r /usr/lib/python3.8/distutil /usr/lib/python3.7/distutil
Then I tried again python3.7 -m pip -V and got
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.7)
Then I tried installing some modules and everything works fine.
I hope this is helpful.
#ciro
I need to do even more to get virtualenv running again (upgraded from 18.04 to 20.04):
sudo cp /usr/lib/python3.8/_sysconfigdata__* /usr/lib/python3.6/
cd /usr/lib/python3.6
sudo ln -s _sysconfigdata_m_linux_x86_64-linux-gnu.py _sysconfigdata_m_x86_64-linux-gnu.py

Categories

Resources