1

I have a question if I use Pyinstaller to convert python file to exe will convert the modules with or not? , because i have python file with a lot of modules and i want to convert it how i can do it and avoiding this issue, Thank u.

    import requests

error:

    ImportError: No module named requests

.

12
  • For the error ImportError: No module named requests tell us are you getting this error before building with pyinstaller or after ? Commented May 31, 2021 at 10:30
  • @WaLidLamRaoui after when i use the file in another computer i didn't install the module in Commented May 31, 2021 at 10:36
  • Ok are you using virtualenv, or you install modules directly to your system? i highly encourage you to use a separate virtual environment for each project . Commented May 31, 2021 at 10:40
  • @WaLidLamRaoui install it directly, idk how to use a virtual environment .new in python language Commented May 31, 2021 at 10:41
  • i thought so, anyway i highly encourage you to learn and use something like virtualenv. so you separate environments for each project of yours. Commented May 31, 2021 at 10:43

1 Answer 1

1

After discussion in comments basically the error is occurring when you try to open the generated file in another computer, however your aren't using any virtual environment so you can install the requirements and try to rebuild again but rather you want a stanalone exe file.

For that use :

   pyinstaller --onefile your-script.py 


   # or pyinstaller -F your-script.py 
   
   ## this should generate a stand alone executable file located in the dist folder.

About your concerns on how pyinstaller works

Does pyinstaller make copies of modules when building ?

The answer is simply : yes , as mentioned in the docs here PyInstaller reads a Python script written by you. It analyzes your code to discover every other module and library your script needs in order to execute. Then it collects copies of all those files – including the active Python interpreter! – and puts them with your script in a single folder, or optionally in a single executable file.

However, the variations of Python and third-party libraries are endless and unpredictable, if something goes wrong you can learn how to fix those issues by reading this page on the docs here

What to generate ?

you can read more here

  1. Create a one-folder bundle containing an executable (default), -D, --onedir

  2. Create a one-file bundled executable. you need to use -F ore --onefile

Finally

I highly encourage you to use separate virtual environment for each project.

Sign up to request clarification or add additional context in comments.

5 Comments

i tryed to make exe file from my py like u told me but when i try to open it i get this error and i couldn't fix it ``` AttributeError: 'NoneType' object has no attribute 'decode' [1252] Failed to execute script pw ```
Ok does the script work when executing python your-script.py before using pyinstaller ? also Please update your question and post the content of your script.py so we have a better understanding of the code
Also did you used a virtual environment ? are you using your own modules etc ? a look at the code and the complete error log would be very helpful to understand where this error is comming from .
i can't post the cod its over 3000 chr, and yes its work when i use python command
Ok if you have a github repo of the code i'm willing to help you later, but for me it seems to be something related to the modules you used because you installed them directly to the system so something went wrong when copying the modules and libs maybe even some data etc, for that can you make a virtual environment for this code and install the required libs in that env and then try to build again. and see if the error is fixed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.