Comments (10)
Hello, I had the same problem, I solved it by replacing the line:
libinjector_path = find_spec('.libinjector', __package__).origin
from pyinjector.py
by :
libinjector_path = "libinjector.cp37-win_amd64.pyd"
Then you have to add the file "libinjector.cp37-win_amd64.pyd"
to the executable, I don't know how to do with pyinstaller or py2exe, I use nuitka, here is the argument to add to the nuitka command :
--include-data-file=C:\Users\********\AppData\Local\Programs\Python\Python37\lib\site-packages\pyinjector\libinjector.cp37-win_amd64.pyd=libinjector. cp37-win_amd64.pyd
hoping to help
J'avais pas vu que t'étais français, si ta besoin d'aide pour faire fonctionner hésite pas
from pyinjector.
Happening to me :/
Tried this, to no avail
Hello, I had the same problem, I solved it by replacing the line:
libinjector_path = find_spec('.libinjector', __package__).origin
from pyinjector.py by :libinjector_path = "libinjector.cp37-win_amd64.pyd"
Then you have to add the file "libinjector.cp37-win_amd64.pyd" to the executable, I don't know how to do with pyinstaller or py2exe, I use nuitka, here is the argument to add to the nuitka command : --include-data-file=C:\Users********\AppData\Local\Programs\Python\Python37\lib\site-packages\pyinjector\libinjector.cp37-win_amd64.pyd=libinjector. cp37-win_amd64.pyd
from pyinjector.
You can do this:
-
Copy the
libinjector.cpPYTHON_VERSION-win_OS_BIT.pyd
file to your project data folder.
•PYTHON_VERSION
is your python version, in my case i havePython 3.10
soPYTHON_VERSION
is310
.
•OS_BIT
you can get usingimport platform; platform.machine().lower()
, in my case it isamd64
.
• In my case, filename islibinjector.cp310-win_amd64.pyd
. -
Now you need to patch pyinjector's
api.py
:
Replace linelibinjector_path = find_spec('.libinjector', __package__).origin
with this:
import sys
if getattr(sys, 'frozen', False):
file_name = f'libinjector.cpPYTHON_VERSION-win_OS_BIT.pyd'
libinjector_path = f'{sys._MEIPASS}/YOUR_PROJECT_DATA_FOLDER/{file_name}'
else:
libinjector_path = find_spec('.libinjector', __package__).origin
• You need to replace YOUR_PROJECT_DATA_FOLDER
with the name of the folder to where you copied file in Step 1
.
• Also you need to replace PYTHON_VERSION
and OS_BIT
to your values.
- Now you can package your python application using PyInstaller, don't forget to add
--add-data YOUR_PROJECT_DATA_FOLDER
argument to your PyInstaller CLI command.
from pyinjector.
Thanks everyone for the issue and the notes. As far as I understand it, this issue is due to me being too lazy to write an actual python extension, and interfacing with native code using ctypes instead. A good workaround is indeed to include the generated pyd
, but to solve this properly, I finally opened a pr to use python c api. It seems to work for me with py2exe. Does it work for you people with nuitka and pyinstaller?
from pyinjector.
Thanks everyone for the issue and the notes. As far as I understand it, this issue is due to me being too lazy to write an actual python extension, and interfacing with native code using ctypes instead. A good workaround is indeed to include the generated
pyd
, but to solve this properly, I finally opened a pr to use python c api. It seems to work for me with py2exe. Does it work for you people with nuitka and pyinstaller?
Nuitka only works if I don't use any options like --standalone and --onefile (nuitka main.py)
For pyinstaller I use auto-py-to-exe because of the GUI and the app just returns an error when trying to run it.
from pyinjector.
Thanks for checking @Whitesun123. So, you checked out the branch I posted, installed it and these errors still occurred? Can you please post your code/commands and the errors you got with nuitka and pyinstaller?
from pyinjector.
I’m on my phone so I can only post the Pyinstaller error:
Traceback (most recent call last):
File "main.py", line 11, in <module>
File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 385, in exec_module
File "pyinjector\__init__.py", line 1, in <module>
File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 385, in exec_module
File "pyinjector\api.py", line 7, in <module>
AttributeError: 'NoneType' object has no attribute 'origin'
in the code all I do is “inject(pid, dll)”
from pyinjector.
This error would only occur in the current version of pyinjector, because the code in the stack trace you posted does not exist in the feature brach. Can you make sure that pyinjector from the feature branch is installed before running pyinstaller?
from pyinjector.
This error would only occur in the current version of pyinjector, because the code in the stack trace you posted does not exist in the feature brach. Can you make sure that pyinjector from the feature branch is installed before running pyinstaller?
Sorry for the late response, switching to the 'python_c_api' branch seems to fix the issue with nuitka and pyinstaller. Both of them built a runnable binary file. Thank you for your help.
Nuitka command:
nuitka --windows-icon-from-ico=C:\Users\white\Desktop\Code\Python\dll_injector\titleLogo.ico --standalone --onefile --disable-console --include-data-file=titleLogo.png=. main.py
Pyinstaller command:
pyinstaller --noconfirm --onefile --windowed --icon "C:/Users/white/Desktop/Code/Python/dll_injector/titleLogo.ico" --add-data "C:/Users/white/Desktop/Code/Python/dll_injector/titleLogo.png;." "C:/Users/white/Desktop/Code/Python/dll_injector/main.py"
from pyinjector.
Thank you for your help :) I released pyinjector==1.3.0
in which this issue is fixed.
from pyinjector.
Related Issues (20)
- [Linux] Failure to inject. HOT 1
- How to use? HOT 11
- undefined symbol: injector_attach HOT 1
- Could not find libc HOT 10
- Verify injector ABI in tests or compile directly using Python-C API HOT 1
- Use the new uninject API in kubo/injector
- Add windows-2022 to CI when issues with pip not finding msvc are solved
- Return DLL Handle HOT 4
- Have appropriate exceptions for different return values from `injector_attach`
- add support on > 3.10 HOT 1
- Help please HOT 1
- Failure to inject on Mac HOT 8
- Build wheels for Mac
- Cannot install on win10 via pip HOT 1
- [Enhancement/Question] inject into Wine processes on Linux HOT 1
- Question! HOT 1
- Add support for windows HOT 6
- pyinstaller problem HOT 1
- How do you use this HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyinjector.