Pythonnet error: dynamic module not initialized properly - python

I have Windows 7 x64 and a Python version 2.7.6 on win32.
The framework installed are:
Microsoft .NET Framework 4.5.2
Microsoft .NET Framework 4 Multi-Targeting Pack.
So, when I run my application he crashs on:
import clr
with this error:
SystemError: dynamic module not initialized properly
I have also rebuild pythonnet with Visual C# 2010 express, with x86 platform, but nothing.
Can anyone help me, please.
And possibly can anyone tell me the required .NET Framework installed for use pythonnet.

I had this behavior too. I fixed it by installing Python.net via pip:
python -m pip install pythonnet (might need to run as Administrator/root)
After installation completes you should not get any error when executing
> python
> import clr

The error happens because of that your clr.pyd cannot find the Python.Runtime.dll. Basically You have already import the clr.pyd successfully, but Your the clr.pyd cannot find the Python.runtime.dll. So in order to make your dll searchable, you need to add the location of your Python.Runtime.dll into the System PATH.
Let's say you have your main.py which import clr and your clr.pyd and Python.Runtime.dll in the same directory, you will just need to add the below few lines at the beginning of your main.py:
import sys
import os
sys.path.insert(0, os.path.abspath('./')) # add the current file location to sys path so that the clr module is searchable

Related

Not able to import Tkinter in Maya 2014

I am using windows 7 and Autodesk Maya 2014.When i am trying to import Tkinter i am getting error.please tell me how to solve error given below ?
How to install any python package in Auto desk Maya 2014 ?
import Tkinter
Error
Error: line 1: ImportError: file C:\Program Files\Autodesk\Maya2014\Python\lib\lib-tk\FixTk.py line 65: DLL load failed: %1 is not a valid Win32 application
I added a few Python modules to Maya with the "addsitedir-trick" explained at the end but not every python module will be playing nicely with Maya.
Python on Windows is built with Visual Studio 2008 Professional. Maya uses it's own Python interpreter but Autodesk builts Maya with another Visual Studio version. This can lead to problems if you insall python modules and try to use them with Maya. Beatuifully explained here (together with a the hard solution of compiling the wanted modules yourself):
http://p-nand-q.com/python/building-python-27-with-vs2010.html
What you can try: Install Python 2.7 on your Windows-box, install the module you want to access in Maya (eg with pip). Now in Maya add your system SitePackages (where you just installed the module to) to your Maya-Python-Interpreter SitePackages like so:
import site
site.addsitedir("/path/to/your/python27/Lib/site-packages")
Even cleaner solution would be to use a virtualenv instead of the global site-packages folder! (That's at least what i have done to get psycopg2 and requests play with Maya)
But as mentioned in the beginning of this answer there is a possibility that this may fail (with strange errors).
By the way: I highly recommend to use pyside instead of Tkinter if you want to do GUI stuff in Maya. Or the Maya-Wrappers preferably via pymel. (http://help.autodesk.com/cloudhelp/2017/ENU/Maya-Tech-Docs/PyMel/ui.html)

QT Webengine for Ubuntu

I have several different qt packages installed for my development environment on Ubuntu 15.04 (3.19.0-51-generic), and I can't seem to get my imports correct. The error I am running into in PyCharm is:
from PyQt5.QtWebEngineWidgets import QWebEnginePage
ImportError: No module named 'PyQt5.QtWebEngineWidgets'
The following packages I have installed already, which I believe to be relevant are as follows:
python3-pyqt5
python3-pyqt5-dbg
python-pyqt5
python-pyqt5-dbg
pyqt5-dev-tools
pyqt5-dev
python-pyqt5.qtwebkit
python3-pyqt5.qtwebkit
python-pyqt5.qtwebkit-dbg
python3-pyqt5.qtwebkit-dbg
What am I missing here? Note that the project explicitly requires the following in its README:
Qt 5.5+
PyQt5.6+
Furthermore, I understand that webengine and webkit are two different things (I was giving it a stab). I can't find any Webengine for PyQT5 anywhere in the official Vivid repository. I tried installing libqt5webengine5-dev and libqt5webengine5 from https://launchpad.net/~ethereum/+archive/ubuntu/ethereum-qt packages with the same result, perhaps I need to add something to Python path. Can anyone lend a hand (Im normally a .NET developer :/)?

Unable to add PyQt module to Python project

I'm struggling to figure out how to include the PyQt module in my Python project. I have tried downloading it from here as a zip file, then including that directory in an environment variable that I called PYTHONPATH. I am running Windows 10, Python 3.5.1, and using PyCharm for my IDE. I was trying to follow the instructions from this question on stackoverflow but I haven't had success and am clearly unsure how to do it.
When I downloaded Python, it was downloaded to my appData folder. The path is as follows users/me/AppData/Local/Programs/Python/Python 35-32...and then a bunch of stuff is in therefor Python. I downloaded the PyQt zip folder and unzipped it to the users/me/AppData/Local/Programs/Python/. After adding the environment variable, PyCharm still isn't able to use the module saying ImportError: No module named 'PyQt4. Can anyone explain how I can import this module successfully? I'm used to Javascript...is there a way to just reference the file? Kind of like how this other stack overflow question is doing it?
Here are the imports that I need:
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.QtWebKit import *
Thanks in advance!
This is how i install Python and PyQt
1 - Install python (Create a folder somewhere like D:\python_dist)
2 - Install Qt
3 - Install PyQt5/PyQt4 with Windows installer ( PyQt5-5.6-gpl-Py3.5-Qt5.6.0-x64-2.exe) https://www.riverbankcomputing.com/software/pyqt/download5
4 - Check paths ...
5 - Open your IDE then try
When you do python, usually you use a virtual_env, and you could need several env, that's why i recommand to create a special python folder
If you are having trouble installing the PyQt library from binary and from pip you could install PyQt from prepackaged whl files.
navigate to the Unofficial Windows Binaries from the University of California, Irvine and download the whl associated with your installed version of Python:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyqt4
Then insall that file via pip by navigating to the directory where you downloaded the whl file via command line and typing in the following:
pip install name-of-whl-file.whl
You also may have to install pip. If that is the case visit this site to learn how to do that:
https://pip.pypa.io/en/stable/installing/

Python & Tide SDK - import external module?

Since python is bundled with the Tide SDK, I can't figure out how to use access external modules. I've tried copying the module folder "Lib/site-packages/YourModuleHere" to the tide SDK directory, and this suggestion here: TIdeSDK Python module import but with no success. The module I'm trying to use is https://github.com/burnash/gspread
Any ideas?
Thanks...
You may try http://www.py2exe.org/index.cgi/Tutorial
to convert your python code to exe with all needed modules then use Ti.Process.createProcess() to call your exe
In current version of TideSDK, loading custom python modules is not supported.It loads default set of Python modules compiled within the SDK.
I've had some luck installing a view external modules by running setup.py install from TideSDK's python.exe
This post helped:
Installing python modules in TideSDK
For Windows 7:
launch powershell
cd into the module folder
run:
C:\ProgramData\TideSDK\Modules\python\1.3.1-beta\python.exe setup.py install
It installs the module in \Lib\site-packages, as it should, and I'm able to use the import function in the python code.
This has worked for PIL and I'm trying to get it to function with pywin32. I'd love to hear if it works for other modules

PyQt 4.7 - ImportError after installing on Windows

I've been trying to install PyQt 4.7 on Vista, but I am getting an ImportError when I try to do: from PyQt4 import QtCore, QtGui.
ImportError: DLL load failed: The specified module could not be found.
I've checked my System Path, and C:\Python31\Lib\site-packages\PyQt4\bin is on there.
I can't run any of the examples, but the Designer, Assistant and Linguist run fine.
I am using ActivePython 3.1, if that makes any difference. And I haven't had any previous version of PyQt installed.
Edit:
I've copied the QtCore4 and GtGui4 dlls to C:\Python31\Lib\site-packages\PyQt4. That fixes some of the examples, but I still can't use the example browser.
Are you sure there is a \bin directory for your version of PyQt?
I am running PyQt 4.4, and all my binaries are right in:
C:\Python31\Lib\site-packages\PyQt4
Which is what I have my path pointing too.
It sounds like PyQt4 was installed improperly... did you run this?
python setup.py install
There shouldn't be a bin there...
Just wanted to chime in that I had the same problem on a WinXP install of:
python 2.7
Qt 4.7.1 (10.05)
PyQt 4.8.1
I used the windows installer version of all 3 of those items.
Copying the contents of the C:\Python27\Lib\site-packages\PyQt4\bin folder up to the main PyQt folder (C:\Python27\Lib\site-packages\PyQt4) stopped the 'dll not found' errors that python was throwing.
Also chiming in. I installed both python 2.6 and PyQt 4.8.3 on a Windows 7 machine using the windows installers (I did NOT run 'python setup.py install').
I tried to run spyder (which requires PyQt 4.4 or greater) and failed because it couldn't find the PyQt .dlls. I copied all the .dlls from the \Lib\site-packages\PyQt4\bin folder to the \Lib\site-packages\PyQt4 folder, and spyder launches just fine.
PyQt installation also depends on the version of python installed on your platform.Python3.+ is incompatible with Python version < 3.x.
I was facing the same problem as I have Python 2.7 installed on my machine but I downloaded the latest binary which was PyQt-Py3.2-x86-gpl-4.9.exe. If you see here the binary has python version also mentioned in name after PyQt which is Py3.2. I uninstalled PyQt and installed PyQt-Py2.7-x86-gpl-4.9.exe which points to Python 2.7 and it fixed the problem.
Probably they could have mentioned the naming convention online or in some documentation to be more simpler.
I had the same problem. I got my program running from within Eclipse but when I tried running it directly from the command line I still got the same error.
I solved it by renaming the C:\Users\Me\AppData\Roaming\Python\Python27\site-packages\PyQt4 directory. (I'm guessing leftovers from a previous PyQt install)
I am using ActivePython.
I think there are at least two possible error conditions
1. ImportError: DLL load failed: The specified module could not be found.
then you have to check your PyQT version is comptible with your python. In other words, if you use python 3.3, then you can only use PyQT for python3.3 and python 3.3 will not work with PyQT for python3.4
This was the problem I met. I solved it with re-install it
2. Import Error: DLL load failed: %1 then something strange on a different encoding Win32.
then it would be a OS problem. If you use 32bit Python then you have to use 32bit PyQt, so do 64bit
Here's how I could fix those errors on Windows 7:
Get the PyQt4 wheel from
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyqt4.
Make sure that the version is exactly the same as your Python version (i.e. Python 3.3 doesn't work with PyQT for Python 3.4). Also make sure to download the 64bit version if you are on a 64bit machine and vice versa.
Extract the wheel with 7zip
Rename the PyQt4-4.11.4.data (or similar) directory to PyQt4
Go to PyQt4\purelib\PyQt4\ and move everything to the root PyQt4 folder. You can delete the purelib folder now
Copy the whole PyQt4 folder to your Python interpreters 'site-packages' folder (e.g. C:\Python34\Lib\site-packages)
Go to PyQt4\data\Lib\site-packages and move all the files to C:\Python34\Lib\site-packages\
In my case I needed MSVCP140.dll. I have solved this problem by dowloading Visual C++ Redistributable for Visual Studio 2015:
https://www.microsoft.com/en-us/download/details.aspx?id=48145
Got this solution from MSVCP140.dll missing
I am using Pyqt4 and Python 3.6 in Windows7.

Categories

Resources