I'm just sruggling with importing modules from nested packages in Python.
After execute command in project root directory:
$ nosetests
Unfortunatelly, i'm still getting logs like this:
======================================================================
ERROR: Failure: ImportError (No module named io_file)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 418, in loadTestsFromName
addr.filename, addr.module)
File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 47, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 94, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "/home/user/dev/ease-ci/easeci-core/tests/lib/io/test_io_facade.py", line 4, in <module>
from lib.io.io_file import file_load, File, file_exist, file_save, file_delete, file_change
ImportError: No module named io_file
And more and more errors like that.
Can someone tell me something help me to resolve my issue? Thanks.
Pycharm put me in error, because if I run test by green arrow, everything is ok.
I'm guessing that you are trying to install a library without pip installed because you used pycharm in a weird way.
Try adding a path to the library which you have to download and then run the import within the code. Cheers!
import tensorflow as tf
https://www.jetbrains.com/help/pycharm/absolute-path-variables.html
Related
I was working with python (which I rarely do) for a simple program that macros some functionalities with certain keyboard inputs. I decided to export the script to a .exe using pyinstaller so I go ahead and run command: pyinstaller --onefile code.py and it generates the code.exe as expected. Only for my .exe to crash instantly. I got a view of the error by running it with cmd and got this
Traceback (most recent call last):
File "code.py", line 1, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "pynput\__init__.py", line 40, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "pynput\keyboard\__init__.py", line 31, in <module>
File "pynput\_util\__init__.py", line 76, in backend
ImportError
[1284] Failed to execute script 'code' due to unhandled exception!
I'm certain there is an explanation to this so here are my imports:
from pynput import keyboard
from pynput.keyboard import Key
from pywinauto import application
from pywinauto.findwindows
import WindowAmbiguousError, WindowNotFoundError
import os
I couldn't seem to find any similar problems on here. Thank you in advance for the help.
In your .spec file, you should add all of your modules as "hidden imports", this usually fixes all module not found errors.
hiddenimport=["pynput","pywinauto"]
Then run pyinstaller with the spec file
pyinstaller my.spec
I'd also ensure you're using a virtual environment during this entire process.
Is this a code error, or something i forgot to install? Please help thank you!
Exact error:
Traceback (most recent call last):
File "launcher.py", line 5, in <module>
bot.run(VERSION)
File "/root/doob/lib/bot/__init__.py", line 61, in run
self.setup()
File "/root/doob/lib/bot/__init__.py", line 47, in setup
self.load_extension(f"lib.cogs.{cog}")
File "/usr/local/lib/python3.8/dist-packages/discord/ext/commands/bot.py", line 660, in load_extension
spec = importlib.util.find_spec(name)
File "/usr/lib/python3.8/importlib/util.py", line 94, in find_spec
parent = __import__(parent_name, fromlist=['__path__'])
ModuleNotFoundError: No module named 'lib.cogs.'
In your setup function you have f"lib.cogs.{cog}", but cog is an empty string or something, so its trying to essentially import lib.cogs. which is not a valid module / does not exist and is causing your error.
it's because file structures work different on linux than Windows.
(how i fixed it, https://stackoverflow.com/a/63931191/12388205)
I tried to install pygments-ipython-console.
In requirements it says:
This needs IPython 1.0+ for sphinxext module
How can I install this module?
I dont find anything in my packet manager (yum).
The following error indicates that the module is not installed:
An error occurred in an add-on.
Please post on the add-on forum:
https://anki.tenderapp.com/discussions/add-ons
Traceback (most recent call last):
File "/usr/share/anki/aqt/addons.py", line 39, in loadAddons
__import__(file.replace(".py", ""))
File "/home/cmueller/Anki/addons/Syntax Highlighting for Code.py", line 2, in <module>
import code_highlight_addon.code_highlight_addon
File "/home/cmueller/Anki/addons/code_highlight_addon/code_highlight_addon.py", line 211, in <module>
for lex in get_all_lexers():
File "/home/cmueller/Anki/addons/code_highlight_addon/pygments/lexers/__init__.py", line 45, in get_all_lexers
for lexer in find_plugin_lexers():
File "/usr/lib/python2.7/site-packages/pygments/plugin.py", line 53, in find_plugin_lexers
yield entrypoint.load()
File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2108, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "build/bdist.linux-x86_64/egg/lexer.py", line 4, in <module>
ImportError: No module named sphinxext.ipython_console_highlighting
Thanks to pokoli I realized that my version was not recent enough.
In the README of pygments-ipython-console it still says version 1.0+ is required, that's a mistake.
I have now updated to version 2.2 but still got an Error:
ImportError: cannot import name IPythonConsoleLexer.
That is because there was a renaming in IPython. There is a fork in the pygments-ipython-console repository where this is fixed. So I had to clone the forked repository instead of the initial one.
I reinstalled according to the readme and now everything works fine.
I'm a beginner in OpenGL/OpenCL.
I'm trying to execute code from this
example, but there is an error:
Traceback (most recent call last):
File "/home/anka-rybalko/workspace/bla/openGL.py", line 99, in initializeGL
self.initialize_buffers()
File "/home/anka-rybalko/workspace/bla/openGL.py", line 61, in initialize_buffers
self.ctx, self.queue = clinit()
File "/home/anka-rybalko/workspace/bla/openGL.py", line 37, in clinit
+ get_gl_sharing_context_properties())
File "/usr/lib64/python2.7/site-packages/pyopencl-2014.1-py2.7-linux-x86_64.egg/pyopencl/tools.py", line 422, in get_gl_sharing_context_properties
from OpenGL import platform as gl_platform, GLX, WGL
File "/usr/lib/python2.7/site-packages/OpenGL/WGL/__init__.py", line 1, in <module>
from OpenGL.raw.WGL.VERSION.WGL_1_0 import *
File "/usr/lib/python2.7/site-packages/OpenGL/raw/WGL/VERSION/WGL_1_0.py", line 48, in <module>
#_p.types(_cs.c_int,_cs.HDC,ctypes.POINTER(_cs.PIXELFORMATDESCRIPTOR))
File "/usr/lib/python2.7/site-packages/OpenGL/raw/WGL/VERSION/WGL_1_0.py", line 13, in _f
return _p.createFunction( function,_p.PLATFORM.WGL,'WGL_VERSION_WGL_1_0',error_checker=_errors._error_checker)
AttributeError: 'GLXPlatform' object has no attribute 'WGL'
As I understand, WGL is an API for Windows OS and not for Linux. Should I somehow specify my platform before? Or how can I fix this?
Thanks in advance!
The code you are using (PyOpenGL 2014.1) is importing two platform-specific modules (WGL and GLX). PyOpenGL should have raised that error as an ImportError (rather than the AttributeError), but it still would have failed.
PyOpenCL has, in the meantime, worked around the issue in their github repository. If you have git installed (and pip) then this should get you a new version (note: not set up for OpenCL development here, so can't actually test this):
pip install git+https://github.com/pyopencl/pyopencl#egg=pyopencl
Maybe someone has a clue about this one. Google, the Logilab.org archives and every other source I tried to determine a solution have turned up empty.
I was trying to get Pylint 2.4 running with PyDev in Eclipse (with Python 2.6) on Windows, but right now I'd be happy simply running pylin at all. I used easy_install to install pylint and it's dependancies. That seemed to work fine. However if I try to run c:\python26\Scripts\pylint.bat , I get the following:
Traceback (most recent call last):
File "C:\Python26\Scripts\pylint", line 5, in <module>
pkg_resources.run_script('pylint==0.24.0', 'pylint')
File "c:\Python26\lib\site-packages\pkg_resources.py", line 489, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "c:\Python26\lib\site-packages\pkg_resources.py", line 1207, in run_script
execfile(script_filename, namespace, namespace)
File "c:\python26\lib\site-packages\pylint-0.24.0-py2.6.egg\EGGINFO\scripts\pylint", line 3, in <module>
from pylint import lint
File "c:\Python26\lib\site-packages\pylint-0.24.0-py2.6.egg\pylint\lint.py", line 31, in <module>
from pylint.checkers import utils
File "c:\Python26\lib\site-packages\pylint-0.24.0py2.6.egg\pylint\checkers\__init__.py", line 44, in <module>
from logilab.astng.utils import ASTWalker
File "c:\Python26\lib\site-packages\logilab_astng-0.22.0py2.6.egg\logilab\astng\__init__.py", line 58, in <module>
from logilab.astng.nodes import *
File "c:\Python26\lib\site-packages\logilab_astng-0.22.0-py2.6.egg\logilab\astng\nodes.py", line 54, in <module>
from logilab.astng.node_classes import Arguments, AssAttr, Assert, Assign, \
File "c:\Python26\lib\site-packages\logilab_astng-0.22.0-py2.6.egg\logilab\astng\node_classes.py", line 27, in <module>
from logilab.astng.bases import (NodeNG, Statement, Instance, InferenceContext,
File "c:\Python26\lib\site-packages\logilab_astng-0.22.0-py2.6.egg\logilab\astng\bases.py", line 28, in <module>
from logilab.common.compat import builtins
ImportError: cannot import name builtins
I mucked around and looked into based.py, but I have no clue what the problem is. My shell path includes C:\python26;c:\Python26\Scripts.
Does this have something to do with lib2to3? Or Python 2.6 compatibility?
Note that I installed pylint using "easy_install pylint", and logilab-common is at the latest 0.56.2.
Thanks!
For me, there is a logilab.common.compat module buried inside the egg "logilab.pylintinstaller-0.15.2-py2.6.egg" in my site-packages folder. Having the logilab_common egg installed, removing the pylintinstaller egg got pylint working in eclipse. I found this out via IPython like so:
In [37]: import logilab.common.compat
In [38]: from logilab.common.compat import builtins
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
C:\Users\Rio\Documents\mcedit\pymclevel\<ipython console> in <module>()
ImportError: cannot import name builtins
In [41]: logilab.common.compat.__file__
Out[41]: 'c:\\python26\\lib\\site-packages\\logilab.pylintinstaller-0.15.2-py2.6.egg\\logilab\\common\\compat.pyc'
Probably you don't have the logilab.common package or the installed version is an old one.
try:
easy_install-2.6 --upgrade logilab-common