ImportError with PySide6/shiboken6 - python

I'm trying to get PySide6 to run in Python 3.8.0. Installation went fine:
C:\>pip install pyside6
Collecting pyside6
Using cached PySide6-6.0.0-6.0.0-cp36.cp37.cp38.cp39-none-win_amd64.whl (62.4 MB)
Collecting shiboken6==6.0.0
Using cached shiboken6-6.0.0-6.0.0-cp36.cp37.cp38.cp39-none-win_amd64.whl (2.3 MB)
Installing collected packages: shiboken6, pyside6
Successfully installed pyside6-6.0.0 shiboken6-6.0.0
but i'm hit with an import error:
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import PySide6
PySide6/__init__.py: Unable to import shiboken6 from , C:\Python38\python38.zip, C:\Python38\DLLs, C:\Python38\lib, C:\Python38, C:\Python38\lib\site-packages
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python38\lib\site-packages\PySide6\__init__.py", line 107, in <module>
_setupQtDirectories()
File "C:\Python38\lib\site-packages\PySide6\__init__.py", line 57, in _setupQtDirectories
import shiboken6
File "C:\Python38\lib\site-packages\shiboken6\__init__.py", line 25, in <module>
from .shiboken6 import *
ImportError: DLL load failed while importing shiboken6: The specified procedure could not be found.
What did i do wrong?

What did i do wrong?
I don't believe you did anything wrong.
I think this was a known bug in shiboken6 versions <=6.0.0. It was reported partly in the PySide bug tracker: PYSIDE-932.
The issue appeared to be that they were attempting to import from a zip file. From the comments in version 6.3.0 of shiboken6.__init__:
# PYSIDE-932: Python 2 cannot import 'zipfile' for embedding while being imported, itself.
# We simply pre-load all imports for the signature extension.
# Also, PyInstaller seems not always to be reliable in finding modules.
# We explicitly import everything that is needed:
The comment says Python 2 cannot import, but it should read PySide2 cannot import because the issue came from Python 3.6 using PySide 2.
The Qt Docs mention using a newer version of virtualenv to fix this problem, but I do not believe virtualenv is the culprit. Moreover, the latest Python 3 versions ship with and use venv. Instead, I believe this was an issue with importing zip files. It may have been resolved when Barry Warsaw/Brett Cannon and their team introduced importlib.resources in newer versions of Python 3, which can particularly help with zip files.
See their talk here:
Barry Warsaw - Get your resources faster, with importlib.resources - PyCon 2018
Ultimately, I believe this was resolved in the latest version of shiboken6 (i.e. 6.3.0).
Give that a try and see if that works.

Related

Cannot import name 'etree' in Python 3.7, how can I get this working?

I'm working through Automate the Boring Stuff with Python, Chapter 13, and can't figure out how to get the python-docx module working. When I try to import it ImportError: cannot import name 'etree' from 'lxml' (<path>,__init__.py). Trying from lxml import etree doesn't work either. I've been at this for days, just installed Anaconda which includes libxml2 and libxslt which are required for lxml and still nothing. Any ideas? I'm extremely lost, there's about 4 or 5 different docs involved with this entire process and I can't make sense of any of it.
Here's a couple of StackOverflow questions I've tried bits and pieces from:
Installing lxml, libxml2, libxslt for Python 3.5 on Windows 10 - This is where I decided to install Anaconda thanks to furas's answer
LXML: Cannot import etree - From here I tried installing different wheels. I already had lxml installed from pip so it didn't matter anyway, but I learned a bit about wheels so that was good.
I also found a .exe but it was for Python 2.7.
I'm using Python 3.7 64 bit on Windows 10.
Besides the solutions above I have uninstalled and reinstalled these packages in two different directories to no avail.
Okay furas, thank you for the tip, here is the Traceback.
C:\Users\...>py
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import lxml
>>> from lxml import etree
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'etree' from 'lxml' (C:\Users\...\AppData\Roaming\Python\Python37\site-packages\lxml\__init__.py)
**MY PERSONAL SOLUTION:**
After messing with this for three days I decided to uninstall every Python release I had on my PC and do a clean install. That was the only way for me to get it working, but it worked! No surprises there I think. I'm assuming there was a problem with how I had Python installed because I had two separate directories with different releases and pip was installing packages in a weird way. It doesn't make sense to me but the problem is solved on my end. I don't know if this will help anyone else.
maybe you have installed both Anaconda and Python.
this case causes confliction between Python scripts.
the solution is deleting Python scripts and packages from Python installed location.
it may be on C:\programfiles\Python (if installed globally) or %USER\AppData\Roaming\Python.

Can not install numexpr (and hence pytables) on windows 7, dll load failing for interpreter.pyd even though it is present

I installed numexpr and pytable using .whl. Installation looked fine but dll import failure keeps coming. Here are the installation details.
PS E:\> pip install --use-wheel --no-index --find-links=.\ numexpr-2.4-cp27-none-win32.whl
Ignoring indexes: https://pypi.python.org/simple
Processing e:\numexpr-2.4-cp27-none-win32.whl
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.6 in c:\python27\lib\site-packages\numpy-1.7.0-py2.7-
win32.egg (from numexpr==2.4)
Installing collected packages: numexpr
--- when using numexpr in pytable ---
E:\bf\pycon2013-master\pycon2013-master>python
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> from numexpr import interpreter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\numexpr\__init__.py", line 41, in <module>
from numexpr.expressions import E
File "C:\Python27\lib\site-packages\numexpr\expressions.py", line 46, in <modu
le>
from numexpr import interpreter
ImportError: DLL load failed: The specified module could not be found.
I had a very similar problem and after a couple of hours, I was able to fix it. I'm sharing my fix and hope it may help someone else like me.
Go to the site below:
https://www.lfd.uci.edu/~gohlke/pythonlibs/
Then download
1) numpy+mkl (it is different from numpy! as Marcel noted)
2) Visual C++ 2017 (x64 or x86 for CPython 3.5, 3.6, and 3.7) redistributable packages (you can find the link on the site above)
3) numexpr
4) pytables
Download the right version for you.
For me it is
numpy‑1.15.3+mkl‑**cp37‑cp37**m‑win_amd64.whl
Since my python version is 3.7
Then from cmd(admin) change directory to the folder where whl is located.
cd 'c:/folder/'
Then run
pip install numpy‑1.15.3+mkl‑cp37‑cp37m‑win_amd64.whl
and so forth.
I found this reference to the fact that numexpr expects numpy + MKL to be present. I've not found any other documentation to this fact.
I had an older version of numpy 1.7.0 from Chris Golkhe numpy-1.7.0-win32-superpack-python2.7.exe which unfortunately I have no idea if that included MKL or not.
I uninstalled the old numpy and installed numpy‑1.9.2+mkl‑cp27‑none‑win32.whl via pip and numexpr imports without issue now.
I am unsure if my problem was older numpy or if it was actually something to do with MKL. Either way, installed a more recent binary fixed it.

Importing wxPython fails in Maya

When I try to import wxPython from Maya (or mayapy), I get an import error:
[/c] ==> mayapy
Python 2.6.4 (r264:75706, May 19 2011, 13:53:43) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\Program Files\Autodesk\Maya2013\Python\lib\site-packages\wx-3.0-msw\wx\__init__.py", line 45, in <module>
from wx._core import *
File "c:\Program Files\Autodesk\Maya2013\Python\lib\site-packages\wx-3.0-msw\wx\_core.py", line 4, in <module>
import _core_
ImportError: DLL load failed: The specified module could not be found.
Question:
How do I make wxPython work with Maya's Python installation?
Context:
I use PyQt, PySide and Tkinter for my UI development with Maya Python. I want to use wxPython just to try it out. I installed the version of wxPython that was meant for Python 2.6/Win64. It is installed in Maya's Python folder: C:\Program Files\Autodesk\Maya2013\Python\lib\site-packages\
I tried installing wx for a standard installation of Python 2.6 and it works fine. That is the reason I am posting this question; I am looking for a solution for why this is happening only for the Maya Python installation and not the other standard Python installation that I have.
I am using:
Maya version: 2013
Maya Python version: 2.6.4
OS: Windows 7, 64-bit.
Thank you for any help or suggestions you can give.
There are a couple of reasons you could be getting that message. Some have reported that this happens if you install a 64-bit wxPython to a 32-bit Python (or vice-versa), although I personally don't know how you could do that. That is something to check though as if you have a 64-bit vs 32-bit mismatch, you will definitely have issues.
The other more likely issue is that you need to install a Microsoft redistributable so that you have the correct DLL that wxPython needs.
"import wx" fails after installation of wxPython on Windows XP
wxPython Import Error: DLL load failed

issues with six under django?

I'm trying to use a package called vcrpy to accelerate the execution of my django application test suite. I'm using django 1.7 on Mac, with Python 2.7.
I added the following couple of lines to one of my tests:
import vcr
with vcr.use_cassette('recording.yaml'):
The result is an import error:
import vcr
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/vcr/__init__.py", line 2, in <module>
from .config import VCR
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/vcr/config.py", line 6, in <module>
from .cassette import Cassette
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/vcr/cassette.py", line 12, in <module>
from .patch import CassettePatcherBuilder
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/vcr/patch.py", line 8, in <module>
from .stubs import VCRHTTPConnection, VCRHTTPSConnection
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/vcr/stubs/__init__.py", line 9, in <module>
from six.moves.http_client import (
ImportError: No module named http_client
The problematic code in the VCR package itself is:
import six
from six.moves.http_client import (
HTTPConnection,
HTTPSConnection,
HTTPMessage,
HTTPResponse,
)
The funny thing: this code seems to run fine when I'm just running it from a plain python console, but it results in the above ImportError under Django or under the django manage.py shell.
Any idea what might be wrong?
( some additional details about the location of the six module:
When I'm running plain python console, I get the following:
Python 2.7.8 (v2.7.8:ee879c0ffa11, Jun 29 2014, 21:07:35)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import six
>>> print six.__file__
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/six.pyc
Doing the same thing, with import django; django.setup(), from manage.py shell results in exactly the same directory and same six.pyc file.
)
Maybe a little bit too late for the original question, but I came here trough Google so for future reference, here's my solution:
Problem
The problem I found is that mac os comes with not only python but also some packages pre-installed. Six is one of those packages and therein lies the conflict. The pre-installed six takes priority over the pip installed six, but pip still gives information based on what it itself has installed (e.g. six 1.9.0 vs 1.4.1).
pre-installed (version 1.4.1):
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/
pip installed (whatever you have installed, for me it was 1.9.0):
/Library/Python/2.7/site-packages/
You can check if this is the case for you by running:
$ python
>>> import six
>>> print six.__file__
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six.py'
Fixing it
The solution is actually quite simple, just put
export PYTHONPATH="/Library/Python/2.7/site-packages:$PYTHONPATH"
in your ~/.bashrc (or whatever file your shell uses). If you've configured your pip to install somewhere else, put that in the pythonpath instead.
I had a similar problem on Fedora 21. The reason for this was 2 installed version of the six 1.2.0 and 1.9.0. I solved this problem by the uninstall six, and re-installation latest version:
pip uninstall six
pip install six
Sounds like a multiple-versions conflict. I solved a similar error by downgrading my version of six (1.9.0 caused the error, as did 1.8.0 and 1.7.0). 1.6.0 works without error.
The error I was getting:
from six.moves import http_client
ImportError: No module named moves

web2py "unable to import requests" even though requests is installed

I am trying to get a web2py application running and I have the following code in one of the controllers.
file name : default.py
import requests
def index():
...
In my currently activated virtualenv, I have installed requests using pip, as you can see below.
(web2pyenv) PS C:\Users\rajesh\Desktop\code\RealPython-Part2\web2py> pip install requests
Requirement already satisfied (use --upgrade to upgrade): requests in c:\users\rajesh\desktop\code\realpython-part2\web2py\web2pyenv\lib\site-packages
Cleaning up...
If I open up a python shell, I can import requests and do the usual stuff.
(web2pyenv) PS C:\Users\rajesh\Desktop\code\RealPython-Part2\web2py> python
Python 2.7.4 (default, Apr 6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.get("http://google.com").status_code
200
>>>
When I try accessing my web2py application, it still throws the following error.
Traceback (most recent call last):
File "gluon/restricted.py", line 224, in restricted
File "C:/Users/rajesh/Desktop/code/RealPython-Part2/web2py/start/applications/pulse/controllers/default.py", line 1, in <module>
import requests
File "gluon/custom_import.py", line 86, in custom_importer
ImportError: Cannot import module 'requests'
Any pointers on what I am doing wrong here?
Most likely you are using the Windows binary version of web2py. This version includes its own Python interpreter, so it doesn't use the Python version you have installed on your machine (or any of its libraries). As long as you have Python installed, you are better off running the source code version of web2py. Running from source, you will be able to import any installed modules.

Categories