Coder Social home page Coder Social logo

Comments (10)

madaraXor avatar madaraXor commented on May 27, 2024

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.

h8rr avatar h8rr commented on May 27, 2024

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.

TerraFaster avatar TerraFaster commented on May 27, 2024

You can do this:

  1. 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 have Python 3.10 so PYTHON_VERSION is 310.
    OS_BIT you can get using import platform; platform.machine().lower(), in my case it is amd64.
    • In my case, filename is libinjector.cp310-win_amd64.pyd.

  2. Now you need to patch pyinjector's api.py:
    Replace line libinjector_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.

  1. 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.

kmaork avatar kmaork commented on May 27, 2024

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.

Whitesun123 avatar Whitesun123 commented on May 27, 2024

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.

kmaork avatar kmaork commented on May 27, 2024

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.

Whitesun123 avatar Whitesun123 commented on May 27, 2024

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.

kmaork avatar kmaork commented on May 27, 2024

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.

Whitesun123 avatar Whitesun123 commented on May 27, 2024

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.

kmaork avatar kmaork commented on May 27, 2024

Thank you for your help :) I released pyinjector==1.3.0 in which this issue is fixed.

from pyinjector.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.