Skip to content

Using pyinstaller to compile a simple code with oracledb throws an error in the executable file #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
horstrand opened this issue Jul 4, 2022 · 6 comments
Labels
question Further information is requested

Comments

@horstrand
Copy link

I am trying to compile a test code that simply connects to an oracle datable using pyinstaller.
I'm doing it with the --onefile option as shown below:

pyinstaller test_oracle.py --onefile

When I later run the executable, at first I got a few errors, just some modules that were missing ('secrets', 'ssl', 'getpass', 'cryptography'). I fixed it with the option --hidden-import from pyinstaller.

After fixing that, a new error showed up, which I have not been able to fix:

Traceback (most recent call last):
File "test_oracle.py", line 1, in
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "oracledb_init_.py", line 38, in
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "oracledb\connection.py", line 39, in
File "src\oracledb\impl/thin/crypto.pyx", line 35, in init oracledb.thin_impl
ImportError: cannot import name pbkdf2
[18124] Failed to execute script 'test_oracle_sac' due to unhandled exception!

I have tried importing the module in different ways and it still does not work.

Any help would be appreciated!

  1. What versions are you using?

oracledb==1.0.1
python 3.10.0
pyinstaller==5.1

@horstrand horstrand added the bug Something isn't working label Jul 4, 2022
@anthony-tuininga anthony-tuininga added question Further information is requested and removed bug Something isn't working labels Jul 7, 2022
@anthony-tuininga
Copy link
Member

This is not a bug in python-oracledb. Running this independently of PyInstaller works correctly, right?

The line containing the error has this:

from cryptography.hazmat.primitives.kdf import pbkdf2

You probably need to make sure that module is availble, too, in your frozen executable. I'm not overly familiar with PyInstaller so you'll have to work with it yourself to figure out how to do that!

@reedark95
Copy link

I have also got the same issue as OP, however I was able to resolve it after struggling with it for some hours. Basically, you will need to specify full path to pbkdf2 module with the --hidden-import flag.

In my case, I already have the .spec file created by PyInstaller, so I just added the path in the 'hiddenimports' field like this -

...
binaries=[],
datas=[],
hiddenimports=['cryptography.hazmat.primitives.kdf.pbkdf2'],
hookspath=[],
...

Once done, I was able to successfully build and run the executable file without any issue

@anthony-tuininga
Copy link
Member

Thanks, @reedark95! @horstrand, does this resolve your issue as well? If so, I think we can close this issue.

@horstrand
Copy link
Author

Yes, it worked very well!
Thanks for the support

@cjbj
Copy link
Member

cjbj commented Sep 9, 2022

Also see #57 for another solution.

@LunRod
Copy link

LunRod commented Sep 21, 2022

Hello everyone, I had the same problem exposed, thanks to this chain of messages I managed to solve it.

However, when I run the .exe and do a query it gives me an error. when I run my code from jupyter, there is no problem.
It says that "data" is not defined and it is where I am storing the query made.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants