Execute file in specific path bash - python

i'm using Stacoan for vulnerability analysis (https://github.com/vincentcox/StaCoAn), i want to use it in a pipeline, but when i run stacoan binary or python script in other path, i obtain errors (using stacoan.py):
Traceback (most recent call last):
File "/home/jenkins/StaCoAn/src/stacoan.py", line 18, in <module>
from helpers.project import Project
File "/home/jenkins/StaCoAn/src/helpers/project.py", line 11, in <module>
from helpers.file import File
File "/home/jenkins/StaCoAn/src/helpers/file.py", line 12, in <module>
class File:
File "/home/jenkins/StaCoAn/src/helpers/file.py", line 15, in File
non_regex_indicator = config.get("ProgramConfig", 'non_regex_indicator')
File "/usr/lib/python3.8/configparser.py", line 781, in get
d = self._unify_values(section, vars)
File "/usr/lib/python3.8/configparser.py", line 1149, in _unify_values
raise NoSectionError(section) from None
configparser.NoSectionError: No section: 'ProgramConfig'
Using stacoan executable:
Traceback (most recent call last):
File "/opt/python/3.6.2/lib/python3.6/configparser.py", line 1138, in _unify_values
KeyError: 'ProgramConfig'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/travis/build/vincentcox/StaCoAn/src/stacoan.py", line 17, in <module>
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "/home/travis/virtualenv/python3.6.2/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
File "/home/travis/build/vincentcox/StaCoAn/src/logger.py", line 19, in <module>
File "/home/travis/build/vincentcox/StaCoAn/src/logger.py", line 25, in Logger
File "/home/travis/build/vincentcox/StaCoAn/src/logger.py", line 41, in __Logger
File "/opt/python/3.6.2/lib/python3.6/configparser.py", line 781, in get
File "/opt/python/3.6.2/lib/python3.6/configparser.py", line 1141, in _unify_values
configparser.NoSectionError: No section: 'ProgramConfig'
[81859] Failed to execute script stacoan
This doesn't occurs if i run it in its own path, i tried a simbolic link, executing using absolute path and build an executable but i still obtains errors.
Thanks!
NOTE: I know is a deprecated repository, but my team want to use it

You could use:
os.chdir(path)
More details here: https://www.geeksforgeeks.org/python-os-chdir-method/

Related

No module named 'messagebox._win32' this platform is not supported: win32

I am trying to make an app using pyinstaller. Code is running fine and working, however, when I convert it into exe file it is throwing an error.
Traceback (most recent call last):
File "messagebox\__init__.py", line 45, in <module>
File "importlib\__init__.py", line 126, in import_module
File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
File "<frozen importlib._bootstrap>", line 1142, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'messagebox._win32'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "dummy.py", line 1288, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
File "messagebox\__init__.py", line 54, in <module>
ImportError: this platform is not supported: win32

Pip error in python when importing modules from pip

When i import modules from pip, like requests i get this error when running in VSCODE:
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: C:\Users\user\AppData\Local\Temp\tmp_6yww79s
The only code I used was:
import requests
I get the same error if i check pip version in terminal or other commands with pip:
pip --version
Full error:
PS C:\Script\Frost_met> & 'C:\Users\jrf\AppData\Local\Programs\Python\Python310\python.exe' 'c:\Users\jrf\.vscode\extensions\ms-python.python-2022.12.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher' '62406' '--' 'c:\Script\Frost_met\frost.py'
Traceback (most recent call last):
File "C:\Users\jrf\AppData\Local\Programs\Python\Python310\lib\importlib\_common.py", line 89, in _tempfile
os.write(fd, reader())
File "C:\Users\jrf\AppData\Local\Programs\Python\Python310\lib\importlib\abc.py", line 371, in read_bytes
with self.open('rb') as strm:
File "C:\Users\jrf\AppData\Local\Programs\Python\Python310\lib\importlib\_adapters.py", line 54, in open
raise ValueError()
ValueError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Script\Frost_met\frost.py", line 4, in <module>
import requests
File "C:\Users\jrf\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\__init__.py", line 147, in <module>
from . import packages, utils
File "C:\Users\jrf\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\utils.py", line 24, in <module>
from . import certs
File "C:\Users\jrf\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\certs.py", line 14, in <module>
from certifi import where
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "C:\Users\jrf\AppData\Local\Programs\Python\Python310\lib\site-packages\wrapt\importer.py", line 177, in _exec_module
notify_module_loaded(module)
File "C:\Users\jrf\AppData\Local\Programs\Python\Python310\lib\site-packages\wrapt\decorators.py", line 470, in _synchronized
return wrapped(*args, **kwargs)
File "C:\Users\jrf\AppData\Local\Programs\Python\Python310\lib\site-packages\wrapt\importer.py", line 136, in notify_module_loaded
hook(module)
File "C:\Users\jrf\AppData\Local\Programs\Python\Python310\lib\site-packages\certifi_win32\wrapt_certifi.py", line 20, in apply_patches
certifi_win32.wincerts.CERTIFI_PEM = certifi.where()
File "C:\Users\jrf\AppData\Local\Programs\Python\Python310\lib\site-packages\certifi\core.py", line 37, in where
_CACERT_PATH = str(_CACERT_CTX.__enter__())
File "C:\Users\jrf\AppData\Local\Programs\Python\Python310\lib\contextlib.py", line 135, in __enter__
return next(self.gen)
File "C:\Users\jrf\AppData\Local\Programs\Python\Python310\lib\importlib\_common.py", line 95, in _tempfile
os.remove(raw_path)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\jrf\\AppData\\Local\\Temp\\tmp23ldltgt'
PS C:\Script\Frost_met>
PS C:\Script\Frost_met> & 'C:\Users\jrf\AppData\Local\Programs\Python\Python310\python.exe' 'c:\Users\jrf\.vscode\extensions\ms-python.python-2022.12.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher' '62406' '--' 'c:\Script\Frost_met\frost.py'
Traceback (most recent call last):
File "C:\Users\jrf\AppData\Local\Programs\Python\Python310\lib\importlib\_common.py", line 89, in _tempfile
os.write(fd, reader())
File "C:\Users\jrf\AppData\Local\Programs\Python\Python310\lib\importlib\abc.py", line 371, in read_bytes
with self.open('rb') as strm:
File "C:\Users\jrf\AppData\Local\Programs\Python\Python310\lib\importlib\_adapters.py", line 54, in open
raise ValueError()
ValueError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Script\Frost_met\frost.py", line 4, in <module>
import requests
File "C:\Users\jrf\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\__init__.py", line 147, in <module>
from . import packages, utils
File "C:\Users\jrf\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\utils.py", line 24, in <module>
from . import certs
File "C:\Users\jrf\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\certs.py", line 14, in <module>
from certifi import where
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "C:\Users\jrf\AppData\Local\Programs\Python\Python310\lib\site-packages\wrapt\importer.py", line 177, in _exec_module
notify_module_loaded(module)
File "C:\Users\jrf\AppData\Local\Programs\Python\Python310\lib\site-packages\wrapt\decorators.py", line 470, in _synchronized
return wrapped(*args, **kwargs)
File "C:\Users\jrf\AppData\Local\Programs\Python\Python310\lib\site-packages\wrapt\importer.py", line 136, in notify_module_loaded
hook(module)
File "C:\Users\jrf\AppData\Local\Programs\Python\Python310\lib\site-packages\certifi_win32\wrapt_certifi.py", line 20, in apply_patches
certifi_win32.wincerts.CERTIFI_PEM = certifi.where()
File "C:\Users\jrf\AppData\Local\Programs\Python\Python310\lib\site-packages\certifi\core.py", line 37, in where
_CACERT_PATH = str(_CACERT_CTX.__enter__())
File "C:\Users\jrf\AppData\Local\Programs\Python\Python310\lib\contextlib.py", line 135, in __enter__
return next(self.gen)
File "C:\Users\jrf\AppData\Local\Programs\Python\Python310\lib\importlib\_common.py", line 95, in _tempfile
os.remove(raw_path)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\jrf\\AppData\\Local\\Temp\\tmp23ldltgt'
PS C:\Script\Frost_met>
Looks like the problem comes from python-certifi-win32, as seen in the error messages. To solve it use the link below there are solutions for python-certifi-win32 problem.
python-certifi-win32 problem with solutions
If these solutions don't work search for python-certifi-win32 uninstall and install process.
Last but not recommended solution uninstall all python files and libraries delete config files, caches and all files related to python and reinstall.
I was running into the same problem, but the error was intermittent. If you are coding your file open/close correctly and still running into this error, make sure you are not synching the files with Dropbox, Google Drive, etc. I paused Dropbox and I no longer see the error.

Python Executable created with pyinstaller fails because of gdal

I am trying to create an executable with pyinstaller from a python project. The project uses osgeo modules gdal and osr:
from osgeo import gdal
from osgeo import osr
pyinstaller runs successfully, but when I try to execute the file I encounter the following errors:
Traceback (most recent call last): File "osgeo_init_.py", line
29, in swig_import_helper File "importlib_init_.py", line 127, in
import_module File "", line 1030, in
_gcd_import File "", line 1007, in _find_and_load File "", line 984, in _find_and_load_unlocked ModuleNotFoundError: No module named 'osgeo._gdal'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "[...].py", line 1, in
File "PyInstaller\loader\pyimod03_importers.py", line 495,
in exec_module File "[...]_init_.py", line 1, in File
"PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "[...]\GeoMap.py", line 1, in File
"PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "osgeo_init_.py", line 45, in File
"osgeo_init_.py", line 41, in swig_import_helper ImportError:
Traceback (most recent call last): File "osgeo_init_.py", line
29, in swig_import_helper File "importlib_init_.py", line 127, in
import_module File "", line 1030, in
_gcd_import File "", line 1007, in _find_and_load File "", line 984, in _find_and_load_unlocked ModuleNotFoundError: No module named 'osgeo._gdal'
On Windows, with Python >= 3.8, DLLs are no longer imported from the
PATH. If gdalXXX.dll is in the PATH, then set the
USE_PATH_FOR_GDAL_PYTHON=YES environment variable to feed the PATH
into os.add_dll_directory(). [3268] Failed to execute script '[removed
name]' due to unhandled exception!
I am using Python 3.9 and pyinsatller 5.0.1, gdal 3.4.2.
Has anyone encountered a similar problem and found a solution?

not showing the server address while using python manage.py runserver in django

while running python manage.py runserver , getting this error as given below. using pycharm
(venv) C:\Users\User\PycharmProjects\PyShop>python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\User\PycharmProjects\PyShop\venv\lib\site-packages\django\template\utils.py",
line 66, in __getitem__
return self._engines[alias]
KeyError: 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\User\PycharmProjects\PyShop\venv\lib\site-packages\django\template\backends\d
jango.py", line 121, in get_package_libraries
module = import_module(entry[1])
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\importlib\__init__.py", li
ne 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\User\PycharmProjects\PyShop\venv\lib\site-packages\django\contrib\admin\templ
atetags\admin_static.py", line 5, in <module>
from django.utils.deprecation import RemovedInDjango30Warning
ImportError: cannot import name 'RemovedInDjango30Warning' from 'django.utils.deprecation' (C:
\Users\User\PycharmProjects\PyShop\venv\lib\site-packages\django\utils\deprecation.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\threading.py", line 917, i
n _bootstrap_inner
self.run()
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\threading.py", line 865, i
n run
self._target(*self._args, **self._kwargs)
File "C:\Users\User\PycharmProjects\PyShop\venv\lib\site-packages\django\utils\autoreload.py
", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\User\PycharmProjects\PyShop\venv\lib\site-packages\django\core\management\com
mands\runserver.py", line 118, in inner_run
self.check(display_num_errors=True)
File "C:\Users\User\PycharmProjects\PyShop\venv\lib\site-packages\django\core\management\bas
e.py", line 396, in check
databases=databases,
File "C:\Users\User\PycharmProjects\PyShop\venv\lib\site-packages\django\core\checks\registr
y.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\Users\User\PycharmProjects\PyShop\venv\lib\site-packages\django\contrib\admin\check
s.py", line 78, in check_dependencies
for engine in engines.all():
File "C:\Users\User\PycharmProjects\PyShop\venv\lib\site-packages\django\template\utils.py",
line 90, in all
return [self[alias] for alias in self]
File "C:\Users\User\PycharmProjects\PyShop\venv\lib\site-packages\django\template\utils.py",
line 90, in <listcomp>
return [self[alias] for alias in self]
File "C:\Users\User\PycharmProjects\PyShop\venv\lib\site-packages\django\template\utils.py",
line 81, in __getitem__
engine = engine_cls(params)
File "C:\Users\User\PycharmProjects\PyShop\venv\lib\site-packages\django\template\backends\d
jango.py", line 25, in __init__
options['libraries'] = self.get_templatetag_libraries(libraries)
File "C:\Users\User\PycharmProjects\PyShop\venv\lib\site-packages\django\template\backends\d
jango.py", line 43, in get_templatetag_libraries
libraries = get_installed_libraries()
File "C:\Users\User\PycharmProjects\PyShop\venv\lib\site-packages\django\template\backends\d
jango.py", line 108, in get_installed_libraries
for name in get_package_libraries(pkg):
File "C:\Users\User\PycharmProjects\PyShop\venv\lib\site-packages\django\template\backends\d
jango.py", line 125, in get_package_libraries
"trying to load '%s': %s" % (entry[1], e)
django.template.library.InvalidTemplateLibrary: Invalid template library specified. ImportErro
r raised when trying to load 'django.contrib.admin.templatetags.admin_static': cannot import n
ame 'RemovedInDjango30Warning' from 'django.utils.deprecation' (C:\Users\User\PycharmProjects\
PyShop\venv\lib\site-packages\django\utils\deprecation.py)
This is caused by django versions. You probably upgraded it or something
There is a conflicts in Django versions as you can see in your error
ImportError: cannot import name 'RemovedInDjango30Warning'
So you can try to create a virtual environment and first uninstall and then re install
pip uninstall django
and then install another version lower then 3.0
pip install django==2.2

I complied my python code using cx_Freeze, code is working good before it & now it is showing this error can anyone help me?

I complied my code using cx_Freeze and before that code is working good in VS Code
every time I try to run program they are showing error
this is actual error
---------------------------
cx_Freeze: Python error in main script
---------------------------
Traceback (most recent call last):
File "C:\Python36\lib\site-packages\pyttsx3\__init__.py", line 20, in init
eng = _activeEngines[driverName]
File "C:\Python36\lib\weakref.py", line 131, in __getitem__
o = self.data[key]()
KeyError: 'sapi5'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python36\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 40, in run
module.run()
File "C:\Python36\lib\site-packages\cx_Freeze\initscripts\Console.py", line 37, in run
exec(code, {'__name__': '__main__'})
File "ZIM.py", line 26, in <module>
File "C:\Python36\lib\site-packages\pyttsx3\__init__.py", line 22, in init
eng = Engine(driverName, debug)
File "C:\Python36\lib\site-packages\pyttsx3\engine.py", line 30, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "C:\Python36\lib\site-packages\pyttsx3\driver.py", line 50, in __init__
self._module = importlib.import_module(name)
File "C:\Python36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 948, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'pyttsx3.drivers.sapi5'
---------------------------
OK
---------------------------
You need to manually inlcude the missing module in cx_freeze setup build_exe_options-
build_exe_options = {'packages': ['pyttsx3.drivers.sapi5']}

Categories

Resources