Pythonnet missing AddReference method - python-3.x

On Win10 1709 x64 PC, installed Python 3.7.4 64-bit and pythonnet-2.4.0-cp37-cp37m-win_amd64.whl. Confirmed clr.pyd and Python.Runtime.dll exist in:
C:\Users\me\AppData\Local\Programs\Python\Python37\Lib\site-packages\
Placed My.Assembly.dll in:
C:\Users\me\AppData\Local\Programs\Python\Python37\DLLs\
This script fails:
import clr
clr.AddReference("My.Assembly")
with error:
AttributeError: module 'clr' has no attribute 'AddReference'
When I remove the 2nd line, import clr succeeds, so it is finding clr.pyd.
Here are my currently-installed packages:
astroid==2.0.4
bottle==0.12.13
certifi==2018.10.15
chardet==3.0.4
colorama==0.3.9
conan==1.9.1
deprecation==2.0.6
distro==1.1.0
fasteners==0.14.1
future==0.16.0
idna==2.7
isort==4.3.4
lazy-object-proxy==1.3.1
mccabe==0.6.1
monotonic==1.5
node-semver==0.2.0
packaging==18.0
patch==1.16
pluginbase==0.7
Pygments==2.2.0
PyJWT==1.6.4
pylint==2.1.1
pyparsing==2.3.0
pythonnet==2.4.0
PyYAML==3.13
requests==2.20.1
six==1.11.0
tqdm==4.28.1
urllib3==1.24.1
wrapt==1.10.11

There is possibly a naming conflict with the clr string styling package, which imports from Lib\site-packages\clr\style_builder.py and contains no AddReference() method.
The correct clr module source code via the pythonnet package looks like this.
Try pip install pythonnet in a fresh environment to be sure there is no package conflict, then retry:
import clr
clr.AddReference()

I had a script named clr.py in my scripts folder :( Deleted it and all is good now.

Related

PyInstaller weird PyQt5.sip import causes a failed EXE [duplicate]

After upgrading to python-pyqt5 5.12-2 I get this error when I try to import from QtWidgets
from PyQt5.QtWidgets import *
Error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'PyQt5.sip'
Any idea on how can I solve this issue?
The reason is a backward incompatible change in PyQt-5.11
In geoptics this fix works on old and new versions:
try:
# new location for sip
# https://www.riverbankcomputing.com/static/Docs/PyQt5/incompatibilities.html#pyqt-v5-11
from PyQt5 import sip
except ImportError:
import sip
As suggested here pyuic5 - ModuleNotFoundError: No module named PyQt5.sip
Try uninstalling and re-installing all PyQt related libraries:
pip uninstall PyQt5
pip uninstall PyQt5-sip
pip uninstall PyQtWebEngine
Then install them again, this will fix:
ModuleNotFoundError: No module named 'PyQt5.sip'
ModuleNotFoundError: No module named 'PyQt5.QtWebEngineWidgets'
PPS.:If you got problems uninstalling the libraries, go to your Python folder, like C:\Users\<USERNAME>\AppData\Local\Programs\Python\Python<PYTHON-VERSION>\Lib\site-packages and manually delete the PyQt folders, them uninstall everything and install again (Make sure you have the latest Python version and upgraded your pip too)
If you're building sip and PyQt5 from source using make files, make sure to check PyQt5 install docs. In particular,
Note
When building PyQt5 v5.11 or later you must configure SIP to create a
private copy of the sip module using a command line similar to the
following:
python configure.py --sip-module PyQt5.sip
If you already have SIP installed and you just want to build and
install the private copy of the module then add the --no-tools option.
You should add PyQt5.sip to hidden imports; that should solve the issue.
I repaired this problem
This problem occurred when upgrading pyqt5 version 5.15.0
There was no problem when I reverted to the previous version.
I have
python -V: 3.7.4
PYQT5 5.14.1 and PYSIDE 5.14.1 works fine
In addition to the answer provided by Tadeu (https://stackoverflow.com/a/58880976/12455023) I would also suggest checking version of your libraries to make sure that they match.
Use pip show <library_name>
This will help you to make sure that no earlier installation is conflicting with your current installation.
In place of library_name use PyQt5, PyQt5-sip, PyQtWebEngine. If any of them is present in the system, then use pip uninstall <library_name>==<version_number> to remove that library.
Once you made sure that no other versions of these libraries are there, then you can reinstall the preferred version of that library.

No module named 'azure.profiles' - Python

I am trying to execute below line of code:
from azure.keyvault.secrets import SecretClient
which internally runs the below code and comes up with an error:
from azure.profiles import KnownProfiles, ProfileDefinition
Below is the error:
ModuleNotFoundError: No module named 'azure.profiles'
Doing "pip freeze" in my environment gives me following modules:
azure-common==1.1.8
azure-core==1.16.0
azure-identity==1.6.0
azure-keyvault==4.1.0
azure-keyvault-certificates==4.3.0
azure-keyvault-keys==4.4.0
azure-keyvault-secrets==4.3.0
azure-mgmt-core==1.3.0
azure-mgmt-storage==18.0.0
azure-nspkg==2.0.0
azure-storage-blob==12.8.0
azure-storage-common==0.37.1
azure-storage-nspkg==2.0.0
Obviously, I do not see anything related to azure-profiles. Below git link directs to installing azure-mgmt-storage to solve the issue, but it didnt help.
https://gitmemory.com/issue/Azure/azure-sdk-for-python/8497/551170157
What am I doing wrong?
I think the reason is that version of azure-common is too low.
Please try the latest version.
pip uninstall azure-common
then
pip install azure-common

pyinstaller not working with several warnings and errors

I am trying to turn my script into .exe file. When I use Pyinstaller I get several warnings and errors and it does not work:
193691 WARNING: Unable to find package for requirement greenlet from package gevent. 193691 WARNING: Unable to find package for requirement zope.event from package gevent. 193691 WARNING: Unable to find package for requirement zope.interface from package gevent.
I installed gevent package but these warnings still appear
2)\anaconda3\lib\site-packages\numpy\__init__.py:138: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
I installed mkl-service package but this message still appears
3)ImportError: DLL load failed while importing _multiarray_umath: The module is not found.
I am using Anaconda navigator and I dont have any additional virtual environment. I have numpy 1.19.2 and Python3.8.
Finally I get PyInstaller.exceptions.ImportErrorWhenRunningHook: Failed to import module __PyInstaller_hooks_0_numpy_core required by hook for module anaconda3\lib\site-packages\PyInstaller\hooks\hook-numpy.core.py. Please check whether module __PyInstaller_hooks_0_numpy_core actually exists and whether the hook is compatible with your version of \anaconda3\lib\site-packages\PyInstaller\hooks\hook-numpy.core.py:
I tried uninstalling anaconda and numpy and reinstalling it. I tried checking Path environment variable. all with no luck.

Pyinstaller --onefile ImportError: No module named 'win32api'

Problem statement:
I can't seem to run
'PyInstaller --onefile myfile.py'
on a file containing
import wmi
It cannot find win32api. I get a popup warning saying python has stopped etc. My console says "ImportError: No module named 'win32api'". I can run 'import win32api', 'import win32com', and 'import WMI' in python directly in the same environment without issue. I fundamentally don't understand what is wrong here.
Error message:
3469 INFO: Loading module hook "hook-pywintypes.py"...
Fatal Python error: Py_Initialize: can't initialize sys standard streams
ImportError: No module named 'win32api'
I have tried:
PyInstaller - ImportError: No module named win32api - 'import os' works fine for PyInstaller and runs fine in python.
No module named 'win32api' - Not very helpful
How to install pywin32 module in windows 7 - This is where I got the SF link (python3.5 amd64 pywin32 version)
ImportError: no module named win32api -
I thought it might be a path thing, but my installation appears to be in the correct place: "C:\Users\myuser\AppData\Local\Continuum\Anaconda3\pkgs\pywin32-220-py35_2\Lib\site-packages\win32"
I can run 'PyInstaller --onefile myscript.py' on other files, and have without issue as long as they don't use the wmi module.
I looked at the win32com _init__.py line 5 where it's messing up and it's just an import statement for win32api.
System:
Windows 7 x64, Python 3.5.3 64bit, Anaconda 4.3.14 64bit, using pyinstaller 3.2.3 (recommended by this thread), with pywin32 220 (with sourceforge download [I know, I tried pip, conda, and easy_install]) and I'm running it in cmder as an admin.
In my case, I couldn't use the module in the python shell, even if original one could. When I execute python shell as an administrator option, it was solved. Try it with administrator execution. I used python version 3.5.2 with windows x64bits.
I face this problem but I install ---> pip install pypiwin32 to solve my problems

Cannot install NumPy from a wheel format

I am trying to install NumPy from a wheel (.whl) file. I get the error:
numpy-1.9.1%2Bmkl-cp34-none-win_amd64.whl is not a supported wheel on this platform.
Details:
Windows 8.1 pro x64, elevated command prompt
Python 3.4.2
Package NumPy from Gohlke's site
File numpy-1.9.1%2Bmkl-cp34-none-win_amd64.whl copied in the pip.exe folder
The log file shows:
d:\Program Files\WinPython-64bit-3.4.2.4\python-3.4.2.amd64\Scripts\pip run on 01/23/15 11:55:21
numpy-1.9.1%2Bmkl-cp34-none-win_amd64.whl is not a supported wheel on this platform.
Exception information:
Traceback (most recent call last):
File "D:\Python34\lib\site-packages\pip\basecommand.py", line 122, in main
status = self.run(options, args)
File "D:\Python34\lib\site-packages\pip\commands\install.py", line 257, in run
InstallRequirement.from_line(name, None))
File "D:\Python34\lib\site-packages\pip\req.py", line 167, in from_line
raise UnsupportedWheel("%s is not a supported wheel on this platform." % wheel.filename)
pip.exceptions.UnsupportedWheel: numpy-1.9.1%2Bmkl-cp34-none-win_amd64.whl is not a supported wheel on this platform.
What is wrong?
Short answer: rename the file to numpy-1.9.1%2Bmkl-cp34-none-win32.whl to install it.
You can check what tags your pip tool accepts for installation by running:
import pip; print(pip.pep425tags.get_supported())
In this case pip is incorrectly detecting your operating system to be 32-bits and the file you're trying to install was win_amd64 in its filename.
If you rename the file to numpy-1.9.1%2Bmkl-cp34-none-win32.whl (which now contains the tags that are considered supported) then you can install the package. It's a trick because the file is still built for 64-bits but this allows you to install the package as intended.
After several tests I think the problem is "win32" or "amd64" itself. I tried replacing those two with "any" and it worked.
In my case, the workaround to install gohlke packages on Python (3.4.4 (AMD64)) was to change the "cp34m" part rather than the "win*" parts in previous answers:
python -c "import pip; print(pip.pep425tags.get_supported())":
[('cp34', 'none', 'win_amd64'), ('py3', 'none', 'win_amd64'),
('cp34', 'none', 'any'), ...
ls -ld *:
matplotlib-2.0.0b3-cp34-cp34m-win_amd64.whl
numpy-1.11.1+mkl-cp34-cp34m-win_amd64.whl
pandas-0.18.1-cp34-cp34m-win_amd64.whl
Change the above names to:
matplotlib-2.0.0b3-cp34-none-win_amd64.whl
numpy-1.11.1+mkl-cp34-none-win_amd64.whl
pandas-0.18.1-cp34-none-win_amd64.whl
For example, pip install matplotlib-2.0.0b3-cp34-none-win_amd64.whl
Processing ...
...Successfully installed matplotlib-2.0.0b3
To add to the list of other possible solutions, I had to upgrade pip itself. The latest binary from Gholke's site had the "cp27m" tag, which didn't show up when I checked the pip tags using:
import pip; print(pip.pep425tags.get_supported())
After I upgraded pip, the wheel didn't work, but just doing a regular pip install numpy worked.
If you have, say, Python 3.4 installed, make sure to install the -cp34- version of the wheel and not -cp35-.
The current WinPython package manager need a two-characters fix to accept to recognize the new NumPy + mkl 'wheel'.
https://github.com/stonebig/winpython/commit/5e13230609a2e9f4d66d98c3776207ce4b4dd050
As a workaround, uninstall the NumPy package:
pip uninstall numpy
Then install it again from cache:
pip install numpy
I had the same problem with several packages after upgrading from 3.4.1 to 3.4.2.
Navigate to the directory where your 'pip.py' sits and then type following on the Windows command line:
..\python.exe pip.py install name_of_package.whl
This should work.
I had the same problem and tried to work it out with the suggested solutions.
I changed win64 to win32 and it didn't work either. But then I changed the name to original and this time it worked! The only extra thing I did was to go offline. That's so strange.
This has nothing to do with your operating system. Uninstall Python 32-bit and install Python 64-bit rather or alternatively find a 32-bit wheel file.

Resources