There was a problem when starting a microservice written in the Nameko framework.
When starting the microservice via the command
nameko run name_file_with_class_microservice
The following exception is thrown:
Traceback (most recent call last):
File "/home/user/.pyenv/versions/project/bin/nameko", line 33, in <module>
sys.exit(load_entry_point('nameko==2.12.0', 'console_scripts', 'nameko')())
File "/home/user/.pyenv/versions/project/lib/python3.9/site-packages/nameko/cli/main.py", line 112, in main
args.main(args)
File "/home/user/.pyenv/versions/project/lib/python3.9/site-packages/nameko/cli/commands.py", line 110, in main
main(args)
File "/home/user/.pyenv/versions/project/lib/python3.9/site-packages/nameko/cli/run.py", line 181, in main
import_service(path)
File "/home/user/.pyenv/versions/project/lib/python3.9/site-packages/nameko/cli/run.py", line 46, in import_service
__import__(module_name)
File "./main.py", line 18, in <module>
from commands.object import ObjectUpdateCommand, ObjectExportCommand
File "./commands/object/__init__.py", line 1, in <module>
from .object_export import ObjectExportCommand
File "./commands/object/object_export.py", line 6, in <module>
from ...exception import ProxyException
ImportError: attempted relative import beyond top-level package
I understand this has to do with the "sys.path" variable and where the launch is coming from. However, I do not understand how to make imports workable, both for the entire project as a whole, and for a separate microservice in it (yes, microservices are combined into one repository, for each of which its own docker-file is written)
Everything works if you specify an absolute path relative to the starting point of the microservice. However, this is not suitable for the whole project, PyCharm indicates import curves, autocompletion does not work, and so on.
Related
I have one of the simplest scripts in the world:
import pandas as pd
and throws errors when I run it:
python3 pandas_import.py
Errors
Traceback (most recent call last):
File "pandas_import.py", line 1, in <module>
import pandas as pd
File "/environment/anaconda3/envs/conda_env/lib/python3.9/site-packages/pandas/__init__.py", line 11, in <module>
__import__(dependency)
File "/environment/anaconda3/envs/conda_env/lib/python3.9/site-packages/numpy/__init__.py", line 155, in <module>
from . import random
File "/environment/anaconda3/envs/conda_env/lib/python3.9/site-packages/numpy/random/__init__.py", line 180, in <module>
from . import _pickle
File "/environment/anaconda3/envs/conda_env/lib/python3.9/site-packages/numpy/random/_pickle.py", line 1, in <module>
from .mtrand import RandomState
File "mtrand.pyx", line 1, in init numpy.random.mtrand
File "bit_generator.pyx", line 40, in init numpy.random.bit_generator
File "/environment/anaconda3/envs/conda_env/lib/python3.9/secrets.py", line 19, in <module>
from random import SystemRandom
File "random.py", line 10, in <module>
FOUT.write(line('a',2))
File "/environment/anaconda3/envs/conda_env/lib/python3.9/gzip.py", line 284, in write
data = memoryview(data)
TypeError: memoryview: a bytes-like object is required, not 'str'
The weird thing is I have a shared conda environment on a shared directory. I can access the exact same conda install via multiple servers. This works fine on one server and errors out like the above on a different server. I even cleared out my .bashrc and .bash_profile scripts and that didn't help.
Any suggestions? I've been banging my head on this one all day. Not sure what's causing a single line python script to error out.
I'm trying to create an exe out of my Python script. After a long journey of problem solving, I finally made it with Pyinstaller. I got a build folder, a dist folder, and the needed exe file.
Now, when I try to run the program, it doesn't work, although it does work in my IDE, PyCharm. If I just click on it, the cmd just opens for a ms and closes right away. If I start it via the cmd, it shows the error you can see below.
Normally there should be a main_window generated by my script, and like I said, it works when I start it from pycharm directly, so the code shouldn't be the problem.
I need the program on another PC without Pycharm at all, so I definitely need this exe file. I hope you can help me. Thanks in advance!
This is the error:
C:\Users\messlaptop\PycharmProjects\Source_code\dist\main_>main_.exe
Traceback (most recent call last):
File "main_.py", line 7, in <module>
import torch
File "C:\Users\messlaptop\PycharmProjects\Source_code\dist\main_\torch\__init__.py", line 643, in <module>
from .functional import * # noqa: F403
File "C:\Users\messlaptop\PycharmProjects\Source_code\dist\main_\torch\functional.py", line 6, in <module>
import torch.nn.functional as F
File "C:\Users\messlaptop\PycharmProjects\Source_code\dist\main_\torch\nn\__init__.py", line 1, in <module>
from .modules import * # noqa: F403
File "C:\Users\messlaptop\PycharmProjects\Source_code\dist\main_\torch\nn\modules\__init__.py", line 2, in <module>
from .linear import Identity, Linear, Bilinear, LazyLinear
File "C:\Users\messlaptop\PycharmProjects\Source_code\dist\main_\torch\nn\modules\linear.py", line 6, in <module>
from .. import functional as F
File "C:\Users\messlaptop\PycharmProjects\Source_code\dist\main_\torch\nn\functional.py", line 11, in <module>
from .._jit_internal import boolean_dispatch, _overload, BroadcastingList1, BroadcastingList2, BroadcastingList3
File "C:\Users\messlaptop\PycharmProjects\Source_code\dist\main_\torch\_jit_internal.py", line 28, in <module>
import torch.package._mangling as package_mangling
File "C:\Users\messlaptop\PycharmProjects\Source_code\dist\main_\torch\package\__init__.py", line 11, in <module>
from .package_exporter import EmptyMatchError, PackageExporter, PackagingError
File "C:\Users\messlaptop\PycharmProjects\Source_code\dist\main_\torch\package\package_exporter.py", line 5, in <module>
import pickletools
ModuleNotFoundError: No module named 'pickletools'
[8896] Failed to execute script 'main_' due to unhandled exception!
I was trying to execute the following command on windows 10 machine using python 3.5.4,
from pywinauto.application import Application
Following is the error which i was receiving
Traceback (most recent call last):
File "C:/Users/bizact/Desktop/PSAV/test.py", line 1, in <module>
from pywinauto.application import Application
File "C:\Program Files\Python35\lib\site-packages\pywinauto\__init__.py", line 72, in <module>
from . import findwindows
File "C:\Program Files\Python35\lib\site-packages\pywinauto\findwindows.py", line 42, in <module>
from . import controls
File "C:\Program Files\Python35\lib\site-packages\pywinauto\controls\__init__.py", line 36, in <module>
from . import uiawrapper # register "uia" back-end (at the end of uiawrapper module)
File "C:\Program Files\Python35\lib\site-packages\pywinauto\controls\uiawrapper.py", line 46, in <module>
from ..uia_defines import IUIA
File "C:\Program Files\Python35\lib\site-packages\pywinauto\uia_defines.py", line 35, in <module>
import comtypes.client
File "C:\Program Files\Python35\lib\site-packages\comtypes\client\__init__.py", line 33, in <module>
gen_dir = _find_gen_dir()
File "C:\Program Files\Python35\lib\site-packages\comtypes\client\_code_cache.py", line 71, in _find_gen_dir
result = os.path.abspath(gen_path[-1])
IndexError: list index out of range
Is there a way i can fix this ?
Try running the script with administrative privileges. Just by looking at the traceback it looks like some cached files that pywinauto import tried to write but later on it wasn't found, and generally the script can't write the file due to permissions. If the above don't work, try installing python somewhere else (C:/Python with full privileges in order to isolate the issue)
This is comtypes issue. It will be fixed soon (EDIT: fixed in comtypes==1.1.7). You can downgrade to one of previous versions: pip install comtypes==1.1.2. Or run script as Administrator as Rodolfo suggested (disabling UAC may not help, need to say explicitly to "run as Administrator" by popup menu).
I get an error when I try to start an exe file with pywinauto. This is my code:
from pywinauto.application import Application
app = Application()
app.Start("D:\dragonboy160\dragonboy160.exe")
As far as I know that should work. app = Application().start("") does not work either. I also tried setting the imports like this: from pywinauto import Application I get this error when I run the python file in PyCharm:
"C:\Program Files (x86)\python.exe" D:/dragonboy160/screenview.py
Traceback (most recent call last):
File "D:/dragonboy160/screenview.py", line 2, in <module>
import pywinauto
File "C:\Program Files (x86)\lib\site-packages\pywinauto\__init__.py", line 40, in <module>
from . import findwindows
File "C:\Program Files (x86)\lib\site-packages\pywinauto\findwindows.py", line 42, in <module>
from . import controls
File "C:\Program Files (x86)\lib\site-packages\pywinauto\controls\__init__.py", line 36, in <module>
from . import uiawrapper # register "uia" back-end (at the end of uiawrapper module)
File "C:\Program Files (x86)\lib\site-packages\pywinauto\controls\uiawrapper.py", line 44, in <module>
from ..uia_defines import IUIA
File "C:\Program Files (x86)\lib\site-packages\pywinauto\uia_defines.py", line 35, in <module>
import comtypes.client
File "C:\Program Files (x86)\lib\site-packages\comtypes\client\__init__.py", line 33, in <module>
gen_dir = _find_gen_dir()
File "C:\Program Files (x86)\lib\site-packages\comtypes\client\_code_cache.py", line 71, in _find_gen_dir
result = os.path.abspath(gen_path[-1])
IndexError: list index out of range
I searched and searched and it seems no other person has had this problem. I also tried opening other .exe files but got the same error. What is causing this error and how can I fix it?
This is an import problem (at the very first line).
This looks like comtypes can't write cached files to Program files without admin privileges. In theory it might be fixed on comtypes side (or by re-installing Python to another folder like C:\Python3x), but you will have to run the script as Administrator anyway because of other OS restrictions (pywinauto will warn about insufficient rights in nearest future, now it's silent).
I had the same problem and I managed to have it fixed by disabling UAC from Windows.
I have PyInstaller and pykeyboard on my computer. I am trying to create a helpful python program and compile it in to a Linux executable with PyInstaller.
Every time I do this, so long as pykeyboard is imported in the script, it creates the executable, but the executable does not run. It comes back with an error.
I've tried compiling my script without pykeyboard and it works, but I would really like to use pykeyboard and get past this error.
Error shown below.
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/root/Desktop/Python/Modules/PyInstaller/PyInstaller-2.1/PyInstaller/loader/pyi_importers.py", line 270, in load_module
File "/home/abigor/Desktop/Scripting/Python/Modules/PyInstaller/PyInstaller-2.1/test/build/test/out00-PYZ.pyz/pykeyboard", line 37, in <module>
File "/root/Desktop/Python/Modules/PyInstaller/PyInstaller-2.1/PyInstaller/loader/pyi_importers.py", line 270, in load_module
File "/home/abigor/Desktop/Scripting/Python/Modules/PyInstaller/PyInstaller-2.1/test/build/test/out00-PYZ.pyz/pykeyboard.x11", line 21, in <module>
File "/root/Desktop/Python/Modules/PyInstaller/PyInstaller-2.1/PyInstaller/loader/pyi_importers.py", line 270, in load_module
File "/home/abigor/Desktop/Scripting/Python/Modules/PyInstaller/PyInstaller-2.1/test/build/test/out00-PYZ.pyz/Xlib.XK", line 63, in <module>
File "/home/abigor/Desktop/Scripting/Python/Modules/PyInstaller/PyInstaller-2.1/test/build/test/out00-PYZ.pyz/Xlib.XK", line 44, in load_keysym_group
ImportError: No module named keysymdef.miscellany
I should also note that the pykeyboard module for Python is actually named "PyUserInput", but to import it from Python you must import "pykeyboard". I forgot to mention that earlier.