Pyinstaller Keyring Windows 32 bit - python

I have the following python test code:
import keyring
print(keyring.get_keyring())
keyring.set_password("a","b","c")
print(keyring.get_password("a","b"))
If I run this code using a 32 bit python or a 64 bit one I obtain the following output (as expected):
<keyring.backends.Windows.WinVaultKeyring object at 0x00000187B7DD6358>
c
My purpose is to build two standalone executable (32bit and 64bit): in order to achieve that I'm using pyinstaller and the following command (test.py is the name of the file containing the python code shown above)
pyinstaller --onefile test.py
If I run the 64 bit exe I obtain the following output (as expected):
<keyring.backends.Windows.WinVaultKeyring object at 0x00000187B7DD6358>
c
Instead, if I run the 32 bit exe I obtain the following output:
<keyring.backends.fail.Keyring object at 0x05463ED0>
Traceback (most recent call last):
File "test.py", line 3, in <module>
keyring.set_password("a","b","c")
File "site-packages\keyring\core.py", line 47, in set_password
File "site-packages\keyring\backends\fail.py", line 23, in get_password
RuntimeError: No recommended backend was available. Install the keyrings.alt package if you want to use the non-recommended backends. See README.rst for details.
[2732] Failed to execute script test
Does anyone know what is going on?
Thanks,
Daniele

Solved using an alternate keyring backend. If I change my code from:
import keyring
print(keyring.get_keyring())
keyring.set_password("a","b","c")
print(keyring.get_password("a","b"))
to:
import keyring
from keyrings.alt import Windows
keyring.set_keyring(Windows.RegistryKeyring())
print(keyring.get_keyring())
keyring.set_password("a","b","c")
print(keyring.get_password("a","b"))
it works.

Setting up the keyrings.alt file from the Keyring Github page does seem to work, and would explain why this was only an issue in Keyring>12, since it was included in the Module before that. I was also able to work around it by installing pip install pywin32 and running the following additions:
import keyring
import win32timezone
from keyring.backends import Windows
keyring.set_keyring(Windows.WinVaultKeyring())
print(keyring.get_keyring())
keyring.set_password("a","b","c")
print(keyring.get_password("a","b"))

Related

ModuleNotFoundError: No module named 'utils.cython_bbox'

I'm a student and a complete newbie, so please forgive me if this is a basic question. I have followed the instructions to run PCL model (https://github.com/ppengtang/pcl.pytorch) on the voc2007 data by following the instructions on the github page.
I'm using Windows 10 64 bit, Python 3.10.5, and as far as I can tell I've installed all dependencies including Visual Studio Code C++ libraries, SDK etc., although I had a lot of trouble trying to install cython_bbox.
When I run in CMD:
python tools/test_net.py --cfg configs/baselines/vgg16_voc2007.yaml \ --load_ckpt Outputs/vgg16_voc2007/$MODEL_PATH \ --dataset voc2007trainval
I get the following:
C:\Users####\py_virtual_env\lib\site-packages\torchvision\models\detection\anchor_utils.py:63: UserWarning: Failed to initialize NumPy: module compiled against API version 0x10 but this version of numpy is 0xf (Triggered internally at ..\torch\csrc\utils\tensor_numpy.cpp:68.)
device: torch.device = torch.device("cpu"),
Traceback (most recent call last):
File "C:\Users####\pcl.pytorch\tools\test_net.py", line 14, in
from core.test_engine import run_inference
File "C:\Users####\pcl.pytorch\lib\core\test_engine.py", line 36, in
from core.test import im_detect_all
File "C:\Users####\pcl.pytorch\lib\core\test.py", line 43, in
import utils.boxes as box_utils
File "C:\Users####\pcl.pytorch\lib\utils\boxes.py", line 54, in
import utils.cython_bbox as cython_bbox
ModuleNotFoundError: No module named 'utils.cython_bbox'
In the lib\utils folder, there are two files: cython_bbox.c and cython_bbox.pyx. This appears to be the root of the issue but I have no idea what exactly the issue is or how to fix it.
For information, I also have:
Requirement already satisfied: cython_bbox in c:\users####\py_virtual_env\lib\site-packages (0.1.3)
I've searched online for a solution but cannot find one.
I'd appreciate any help.

PyInstaller SSL error with requests module - missing module ssl (_ssl)

In my python script, I use the requests module to call an API to GET and POST data.
Python environment: anaconda3, python 3.7 / packages: requests 2.24.0, pyinstaller 3.6, openssl 1.1.1h...
I have the following problem with the EXE-file generated by PyInstaller: When I run this file, I get the following error message. This error doesn't occur when I run my script from Python:
Traceback (most recent call last):
File "site-packages\PyInstaller\loader\rthooks\pyi_rth_certifi.py", line 13, in <module>
File "c:\programdata\anaconda3\envs\...\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
File "ssl.py", line 98, in <module>
ImportError: DLL load failed: The specified module could not be found.
[20188] Failed to execute script pyi_rth_certifi
If I follow to the excepted error lines (ssl.py):
import _ssl # if we can't import it, let the error propagate
Why can't ssl be imported?
I searched a long time in serveral post on SO but all these answers didn't help, ex.:
Python Requests throwing SSLError
Python Requests - How to use system ca-certificates (debian/ubuntu)?
Twilio Python Module Errors After Compiling
Fixing SSL certificate error in exe compiled with py2exe (or PyInstaller)
Does anyone have an idea how to fix this?
If you need more informations, please write a comment. THX
EDIT: (for Mooncrater's comment)
added Screenshot from python console, entered:
import _ssl
EDIT 2:
Tested "FIX" from SO Question:
Python SSL Import Error in PyInstaller generated executable
-> this didn't fix my problem
EDIT 3: Answer by cbolwerk
THX for your answer, this works!
Python 3.7 anaconda environment - import _ssl DLL load fail error
An additional fix is to install the latest OpenSSL Lib, I used 1.1.1h package in my python script, on my PC was installed an older version and that causes the error too.
cbolwerk's answer I tested on a PC where NO OpenSSL is installed and , as I wrote, it works!
If you can import ssl in the python within your environment, it means that the ssl module is probably inside your environment. This answer mentions the files you can look for inside your environment. They are either inside your env/Library/bin or env/DLLs. I think you have these installed, but pyinstaller doesn't recognize them. To make sure that pyinstaller knows these files, you can add them to datas. This can be edited in the command when building the .exe file or in the .spec file that is probably created when you have run this command once. This link may be useful there.
In short, add the paths of the DLLs I mentioned to the datas (or binaries inside .spec actually) so that they are recognized by pyinstaller.
So either run the command
pyinstaller --onedir --add-data libcrypto-1_1-x64.dll;. --add-data libssl-1_1-x64.dll;. myscript.py
or change your .spec to something like
datas = [('/path/to/libcrypto-1_1-x64.dll', '.'), ('/path/to/libssl-1_1-x64.dll', '.'),
(...) ]
...
a = Analysis(...,
datas=datas,
...)
...
and then run
pyinstaller --onedir myscript.spec
This fixed DLL issues for me at least.

Installing SIP for Python 2.7 on windows 10

I have seen many threads that have a high level of ambiguity and go off on tangents from the original question, often assuming much about the authors ability, so I am hoping that if I am direct and concise with my information, I will get an answer that is in line with the requirement. I know that the serious programmers will have seen this many times, in many formats, so please just bear with me as this is doing my head in. Please do not just post a link to some other answer as I rarely find that helps with my current issue.
I am not a hardcore programmer, I find the compiling, sourceball, tar, gz all nonsense to be honest and am looking for the easiest way to install sip for python on my machine. I have installed various versions of mingw32, mingw64 to the point that I don't know which one is best to use. I am assuming that the one here: C:\Program Files\mingw-w64 is the one, considering I am using 64 bit, but do the others I have installed impact on this?
I also installed versions of mysys:
C:\msys\1.0,
C:\msys64, but I still m unclear what and why etc, despite trying to read the docs that came with them.
I have windows 10, 64 bit professional edition.
I have python 2.7
I have installs of mingw, 32 bit and 64 bit in various locations, due mostly to not fully understanding what exactly it was or where it should go. I found zips of it and exes, so I got a bit confused.
I downloaded the sip package and unpacked it to here: C:\Python27\Lib\site-packages\sip-4.19.3 and it has the configure.py file in it. So far, so good.
I used a CMD window, changed directory to: C:\Python27\Lib\site-packages\sip-4.19.3 and then used the command: python configure.py to create the Makefile file which is what I believe is supposed to happen.
I then opened the mingw64 shell, changed directory to the above sip folder and typed: python configure.py again, just to be sure I would get a response and create the files again, probably should not have done so, but hey ho, at this point, I am quite frustrated with it and trying to do anything with what I have, which I know is poor practice. (see image 1.)
image 1: configure.py executed
From what I have read, I should use the make function that comes with Mingw64, but I tried the following, which also includes the configure.py code, but nothing seems to work when trying to use the Makefile file that was created via the configure.py process.
c:\Python27>cd ./Lib/site-packages/sip-4.19.3
c:\Python27\Lib\site-packages\sip-4.19.3> python configure.py
This is SIP 4.19.3 for Python 2.7.13 on win32.
The SIP code generator will be installed in C:\Python27.
The sip module will be installed in C:\Python27\Lib\site-packages.
The sip.pyi stub file will be installed in C:\Python27\Lib\site-packages.
The sip.h header file will be installed in C:\Python27\include.
The default directory to install .sip files in is C:\Python27\sip.
Creating siplib\sip.h...
Creating siplib\siplib.c...
Creating siplib\siplib.sbf...
Creating sipconfig.py...
Creating top level Makefile...
Creating sip code generator Makefile...
Creating sip module Makefile...
c:\Python27\Lib\site-packages\sip-4.19.3> Makefile
'Makefile' is not recognized as an internal or external command,
operable program or batch file.
c:\Python27\Lib\site-packages\sip-4.19.3> make Makefile
make: Nothing to be done for `Makefile'.
c:\Python27\Lib\site-packages\sip-4.19.3> Makefile Makefile
'Makefile' is not recognized as an internal or external command,
operable program or batch file.
c:\Python27\Lib\site-packages\sip-4.19.3>
So now I am at an impasse. I have the locations of my mingw versions and the msys in my path environment variable and I have done just about everything I have looked at on the web. I realise that its an order of things, but I really wish there were just executables for these modules and supporting tools as this compiling is a ball ache.I tried opening a python shell and importing sip.
>>> import os, sys
>>> import sip
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import sip
ImportError: No module named sip
>>> import sipconfig
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import sipconfig
ImportError: No module named sipconfig
>>> from sip import sip
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
from sip import sip
ImportError: No module named sip
>>> from sipconfig impport sip
SyntaxError: invalid syntax
>>> from sip import *
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
from sip import *
ImportError: No module named sip
So, if anyone has read through this and has a definitive answer as to what I am doing wrong, I would appreciate it.
make/nmake or make/nmake install cant be done from cmd and python path; instead using mingw or visual studio tools.
In windows search for prompt or Visual studio tools to open VS Command promt and from there cd--> sip file location (before this run configure.py present in sip folder)
Now run the commands nmake and then nmake install

Python line_profiler not finding module

I recognize that this is an installation failure on my part, and I'm sorry to lay this uninteresting and inconsequential question at your feet, but for the life of me I can't manage to figure out what is going wrong and I've run out of ideas. I'm hoping someone will be able to quickly point out the obvious.
I am trying to profile a python script (using Kern's line_profiler), and the script needs to load the netCDF4 module. I have installed both line_profiler and netCDF4 with pip. Both are reported as present and updated when I queue pip for the list of installed packages.
Without using the profiler, my script runs without problems, meaning that the netCDF4 module is loaded properly. However, if I run 'kernprof -l -v myscript.py' from the "myscript" directory, I get the following error:
Traceback (most recent call last):
File "/usr/local/bin/kernprof", line 9, in <module>
load_entry_point('line-profiler==1.0', 'console_scripts', 'kernprof')()
File "Library/Python/2.7/site-packages/kernprof.py", line 221, in main
execfile(script_file, ns, ns)
File "myscript.py", line 5, in <module>
from netCDF4 import Dataset
ImportError: No module named netCDF4
I am running Python from an installation at /opt/local/bin/python, which is listed first in my PATH.
So, in any case, if the default Python version that I have set is the same as that which appears first in my PATH, and that default version is able to access the netCDF4 module, why isn't line_profiler?
kernprof has a shebang that redirects to the default python install which doesn't have all the required modules.
You can force the use of your "complete" python install by doing:
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/‌​Resources/Python.app‌​/Contents/MacOS/Pyth‌​on /usr/local/bin/kernprof -l -v myscript.py
So shebang is ignored, and you run the profiler with the version of python containing all the required packages.

Python GUI2Exe Application Standalone Build (Using Py2Exe)

I am trying to build a Python Script into a stand alone application. I am using GUI2Exe. My script uses selenium package. I have it installed.
Project compiles fine and runs on python command line directly but fails to build a stand alone because it is referring to folder:
ERROR: test_file_data_extract (__main__.FileDataExtract)
----------------------------------------------------------------------
Traceback (most recent call last):
File "File_data_extract.py", line 18, in setUp
File "selenium\webdriver\firefox\firefox_profile.pyc", line 63, in __init__
IOError: [Errno 2] No such file or directory: 'C:\\users\\username\\PycharmProjects\\Python_27_32bit\\file_data_extract\\dist\\File_data_extract.exe\\selenium\\webdriver\\firefox\\webdriver_prefs.json'
It is looking for selenium package is located at :
C:\Users\username\Anaconda2_Py27_32bit\Lib\site-packages\selenium-2.48.0-py2.7.egg\selenium\webdriver\firefox
where C:\Users\username\Anaconda2_Py27_32bit is where I installed Anaconda Python 2.7, 32 bit version. By default it is looking for in \dist\filename.exe folder.
I was able to build it using bbfreeze. It works great.
First I had to install bbfreezee via pip (one time only):
pip install bbfreeze
Create a build_package.py file as:
from bbfreeze import Freezer
f = Freezer("project_name", includes=("selenium","SendKeys",)) #list problem packages here to manually include
f.addScript("project_name_script.py")
f() # starts the freezing process
Build project:
python build_package.py bdist_bbfreezee
in folder project_name where project_name_script.py sits you find project_name_script.exe with all the include packages including selenium and sendkeys. When you distribute the package you need to distribute entire project_name because it contains all dependent library dlls (python .pyd).
More details refer official bbfreezee here:
https://pypi.python.org/pypi/bbfreeze/#downloads

Categories

Resources