VSCode and PyOpenGL import errors? - python

Running this code in normal IDLE is completely fine.
import OpenGL.GL as gl
However in VSCode, I get an import error.
No module named 'OpenGL.GL'; 'OpenGL' is not a package
File "C:\Users\Fluffy\Desktop\OpenGL.py", line 1, in <module>
import OpenGL.GL as gl
File "C:\users\fluffy\desktop\<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\users\fluffy\desktop\<frozen importlib._bootstrap_external>", line 678, in exec_module
File "C:\users\fluffy\desktop\<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "C:\users\fluffy\desktop\<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "C:\users\fluffy\desktop\<frozen importlib._bootstrap>", line 971, in _find_and_load
File "C:\users\fluffy\desktop\<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\users\fluffy\desktop\<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
File "C:\users\fluffy\desktop\<frozen importlib._bootstrap>", line 971, in _find_and_load
File "C:\Users\fluffy\Desktop\OpenGL.py", line 1, in <module>
import OpenGL.GL as gl
Furthermore, I uninstalled PyOpenGL and noticed that VSCode's intellisense found an existing OpenGL module within python:
link
I'm pretty sure it has something to do with VSCode's way of importing modules from python.
NOTE: I tried reinstalling the PyOpenGL in many different ways, the error still persists.

Related

No file found when converting a python project with NUITKA with library OWLREADY2

After I converted my python project with NUITKA and I started running the following message appeared:
Owlready2 * Warning: optimized Cython parser module 'owlready2_optimized' is not available, defaulting to slower Python implementation
Traceback (most recent call last):
File "/user/try.dist/try.py", line 1, in <module>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "/user/try.dist/owlready2/__init__.py", line 35, in <module owlready2>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "/user/try.dist/owlready2/reasoning.py", line 41, in <module owlready2.reasoning>
FileNotFoundError: [Errno 2] No such file or directory: '/user/try.dist/owlready2/pellet'
Indicating that after I compiled the program some files were not found.
The code that I run was python3 -m nuitka --follow-imports --enable-plugin=numpy --onefile try.py
and the code that I compiled was just simple this:
from owlready2 import *
onto = get_ontology("file:///user/ontologies/try.owl").load()
with onto:
types.new_class("Drug", (Thing,))
onto.save()
So simple there was something wrong with the library.
If anyone knows what to do it will be helpful.
Thanks in advance.
I have changed the location of the file for privacy

"Cannot change thread mode after it is set" RunTime error in Python

I created a project that displays a Windows toast notification using the 'winrt' module. When I run my code in PyCharm, the script executes normally until completion. After compiling using PyInstaller and running the generated exe, I get an error for one of the 'winrt' imports:
Traceback (most recent call last):
File "notification.py", line 1, in <module>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "message.py", line 1, in <module>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "winrt\__init__.py", line 4, in <module>
RuntimeError: Cannot change thread mode after it is set.
[9720] Failed to execute script 'notification' due to unhandled exception!
My imports for 'winrt' are:
import winrt.windows.ui.notifications as notifications
import winrt.windows.data.xml.dom as dom
If anyone one knows why I get this error, I would appreciate any help!

pyInstaller having trouble bundling a package containing SWIG modules

I’m running into an issue getting pyInstaller to bundle a module that contains SWIG modules. I have followed each of the guidelines listed in the pyInstaller doc which details SWIG support.
I get the following error when running the exe:
# sphinxbase._ad_win32 not found in PYZ
Traceback (most recent call last):
File "StartListening.py", line 10, in <module>
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "c:\users\allen\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\sphinxbase\__init__.py", line 35, in <module>
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "c:\users\allen\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\sphinxbase\ad_win32.py", line 32, in <module>
File "site-packages\sphinxbase\ad_win32.py", line 31, in swig_import_helper
File "importlib\__init__.py", line 126, in import_module
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'sphinxbase._ad_win32'
However, sphinxbase._ad_win32 does exists as a pyd file. I’m running Windows 10; why is pyInstaller having trouble bundling this module?
The third-party package I’m ultimately trying to import is SpeechRecognition which depends on pocketsphinx which depends on sphinxbase which is the module that is having issues.
Here is the object reference returned by
importlib.import_module('sphinxbase._ad_win32')
in the SWIG-generated python wrapper if that is helpful to someone:
<module 'sphinxbase._ad_win32' from 'C:\\Users\\bob\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\site-packages\\sphinxbase\\_ad_win32.pyd'>
Python version: 3.6.5
Edit: After some more research, I tried adding the .pyd to the 'binaries' list in the .spec file as well as adding 'sphinxbase._ad_win32' to the 'hidden-imports' list and combinations there-between, but this did not work either. The binary is there, in the correct location, I can't figure out why the bundled app can't find it.

Program doesn't work beyond py2exe

My code is worked well, when I used the raw py file. But when I compiled with py2exe, it will drop an AttributeError:
File "test.py", line 1, in <module>
import wmi
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "C:\Python34\lib\site-packages\zipextimporter.py", line 86, in load_module
return zipimport.zipimporter.load_module(self, fullname)
File "C:\Python34\lib\wmi.py", line 88, in <module>
from win32com.client import GetObject, Dispatch
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "C:\Python34\lib\site-packages\zipextimporter.py", line 86, in load_module
return zipimport.zipimporter.load_module(self, fullname)
File "C:\Python34\lib\site-packages\win32com\__init__.py", line 6, in <module>
import pythoncom
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "C:\Python34\lib\site-packages\zipextimporter.py", line 86, in load_module
return zipimport.zipimporter.load_module(self, fullname)
File "C:\Python34\lib\site-packages\pythoncom.py", line 3, in <module>
pywintypes.__import_pywin32_system_module__("pythoncom", globals())
AttributeError: 'module' object has no attribute '__import_pywin32_system_module__'
When I backported my code to 2.7, It will worked well, but on on winpe10 (Windows Preinstallation Environment, very thin version of win10) drop same error.
On winpe 5 (it is thin version of win8.1) work as well.
My example code:
import wmi
def getWmiData(wmiProperty, wmiClass, wmiNamespace='cimv2'):
"""Return array of strings."""
wmiValues = []
wmiCursore = wmi.GetObject('winmgmts:\\root\\' + wmiNamespace)
wmiQuery = 'SELECT ' + wmiProperty + ' FROM ' + wmiClass
for item in wmiCursore.ExecQuery(wmiQuery):
wmiValues.append(str(item.__getattr__(wmiProperty)))
return wmiValues
print(getWmiData('SystemSKU', 'MS_systeminformation', 'wmi')[0])
Basic py2exe settings:
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'compressed': True},},
console = ['test.py'],
)
Tried versions:
python 2.7.11, 2.7.12, 3.4.4
py2xe: 0.6.9, 0.9.2.2
pywin32: 219, 220
wmi: 1.4.9
Summary: How can I use wmi module with py2exe on the right way?
Since I did clearly reinstall python 2.7 (and of course the necessary modules), everything works on my windows 10, however on the winpe 10 still did not!
I had to add wmi packages to the winpe image, the previous winpe version contains it by default! Now It works on winpe as well.
(I can't understand it. If I know well, wmi is one of the most used tool on winpe!)
With this two lines commands:
Dism /Add-Package /Image:"C:\WinPE_amd64\mount" /PackagePath:"C:\Program Files\Windows Kits\8.1\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-WMI.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64\mount" /PackagePath:"C:\Program Files\Windows Kits\8.1\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-WMI_en-us.cab"

AttributeError in Py2exe

I made my py file executable using py2exe. My setup.py is as follows:
from distutils.core import setup
import py2exe
setup(windows=['main.py'])
When I tried to run main.exe, I get an error and was referred to main.log which reads:
Traceback (most recent call last):
File "main.py", line 20, in <module>
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "C:\Python34\lib\site-packages\pandas\__init__.py", line 7, in <module>
from . import hashtable, tslib, lib
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "<loader>", line 10, in <module>
File "<loader>", line 6, in __load
File "pandas\tslib.pyx", line 2839, in init pandas.tslib (pandas\tslib.c:79846)
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "<loader>", line 10, in <module>
File "<loader>", line 6, in __load
File "pandas\algos.pyx", line 64, in init pandas.algos (pandas\algos.c:179610)
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "<loader>", line 10, in <module>
File "<loader>", line 6, in __load
File "pandas\lib.pyx", line 1, in init pandas.lib (pandas\lib.c:77889)
AttributeError: 'module' object has no attribute '__pyx_capi__'
It looks like line 20 in my main.py file (import pandas as pd) triggered the problem. This type of error is referenced in a pull request here and they suggested adding a blank __init__.py file. I did so and got same result. I found a well commented post here (not directly dealing with py2exe) that suggests this might be due to mutual top-level imports or circular dependencies. This problem seems well known and has been mentioned at least twice on Stackoverflow in the past year (e.gs: here and here) but no clear solution has been given.
Perhaps we can get more clarity now with your feedback.
Python 3.4.2; py2exe 0.9.2.0
Was running into the same issue with pandas, but I got it working after updating to the most recent version.
It seems this error was recently addressed, and was resolved in Pandas 15.2
https://github.com/pydata/pandas/issues/8602
I was running in the same errors with Python 3.4.4.
My solution was to fix the import statement in C:\Pythob34\lib\site-packagespythoncom.py.
Original:
import pywintypes
pywintypes.import_pywin32_system_module("pythoncom", globals())
Changed To:
from pywintypes import import_pywin32_system_module
import_pywin32_system_module("pythoncom", globals())

Categories

Resources