5

I have a very simple application made on python(v 3.6), and I wanted to freeze it using pyinstaller.I have made the app using an environment created with anaconda, and I installed there the packages I needed(youtube_dl). I need help on how to use pyinstaller for my app(Main.py) using the environment I created with all its packages inside it. If I run "pyinstaller Main.py" I get this error:

Traceback (most recent call last):
  File "Main.py", line 7, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 631, in exec_module
    exec(bytecode, module.__dict__)
  File "youtube_downloader.py", line 3, in <module>
ModuleNotFoundError: No module named 'youtube_dl'
[2708] Failed to execute script Main
logout

How can I make pyinstaller use the environment I created at anaconda´s directory?

AMC
  • 2,642
  • 7
  • 13
  • 35
Gonzalo
  • 51
  • 1
  • 1
  • 2

4 Answers4

7

I reinstalled pyinstaller from anaconda prompt by issuing

conda install -c conda-forge pyinstaller

and it worked for me .

Bussller
  • 1,961
  • 6
  • 36
  • 50
piping piping
  • 71
  • 1
  • 4
3

Looks like you installed the youtube_dl in the anaconda environment and you are running the pyinstaller outside the anaconda environment and it can't find the needed module. Did you try just doing pip install youtube_dl before pyinstaller Main.py?

Michu93
  • 5,058
  • 7
  • 47
  • 80
Ontamu
  • 201
  • 1
  • 5
  • Yes! Thanks, that worked for me. But, I always use anconda enviroments to not conflict between packages, so, do you know how could I use pyinstaller inside that anaconda enviroment?? Anyway, thanks dude! – Gonzalo May 18 '18 at 13:22
  • 1
    Hello, probably you can install pyinstaller inside the anaconda environment and run it from there. Haven't tried it myself but it should work. – Ontamu May 21 '18 at 10:21
0

If you failed to run piping piping's answer.

Eg:

  • Using a very old version of Anaconda and you still have to use it.
  • Using very old pip.
  • You cannot access to pypi from host machine.

You may install pyinstaller manually.

Prerequisite

Assuming you have setuptools installed.

Example: PyInstaller 3.5 (for python 2.7) on linux

  1. Download PyInstaller 3.5

Check the requirements.txt

pefile; sys_platform == 'win32'
macholib; sys_platform == 'darwin'
altgraph  # <== you need this

dis3; python_version < '3.0' #<== and this
pywin32-ctypes; sys_platform == 'win32'
  1. Download and install dis3

    1. tar xzf dis3-0.1.3.tar.gz
    2. cd dis3-0.1.3
    3. python setup.py install or /somewhere/your/python2.7 setup.py install
  2. Download and install altgraph

    • Same as dis3
  3. Install PyIstaller

    • Same as above.
Louis Go
  • 2,213
  • 2
  • 16
  • 29
0

I had this issue and had to post my answer, for all the long and way too complicated responses.

  1. If you have pyninstaller (or don't), activate your conda environment

conda activate "envName"

You can get your environment name in many ways, an easy one is just opening Anaconda (the UI) > Environment (on the left) and your enviornment name is listed in the middle column right next to where you clicked.

  1. Pip install pyinstaller.

If you have it, the first like will be like "Requirement already satisfied: pyinstaller in [Path]"

If you don't have it installed, it will simply install it and the same logic applies, take the path from there. Make sure it says ":pyinstaller in" then copy that path.

  1. To run pyinstaller from your conda environment:

python [Full library path\pyinstaller] –onefile [your script]

The idea is it needs the main function NOT pyinstaller.py so don't bother looking for that specifically.

Hope this helps.