Using pyinstaller with two python environments - python

I'm using pyinstaller to pack one .py file into .exe. I have two Python3 environment on my WIN10 64-bit computer. One is from Anaconda and the other is Python3-32bit which is installed separately. This .py file is produced by Anaconda Python environment.
After I installed pyinstaller, I set the environment variable PATH like this:`
PATH=PATH;C:\Anaconda3\Scripts;C:\Python35-32\Scripts;
However, when I enter pyinstaller file.py it throws me lots of warnings:
It seems that pyinstaller searches dependencies in Python35-32's lib folder rather than Anaconda's. How can I make it searche dependencies under Anaconda's lib folder?
`

Did you install pyinstaller using pip or using (ana)conda? if so, check whether pip is the python3-32bit or the anaconda one with:
pip -V
This will tell you if pip, and hence pyinstaller, was installed on the 32-bit interpreter, hence why it's looking in that particular folder.
solution would be to install pyinstaller using conda or within the anaconda IDE. Probably would need to uninstall pyinstaller from python3-32bit

Related

Executable file says no module found even though package is installed in Conda environment

I created a Python executable file using PyInstaller in a Conda environment called citygrows_demo.
I ran conda install nltk to install this package into the environment, and when I run conda list I can see the nltk package is installed.
I then created the executable file called common_fields_script.exe using the command
pyinstaller "C:\Users\lakna\OneDrive\Desktop\CityGrows\common_fields\common_fields_script.py" --onefile --icon="C:\Users\lakna\OneDrive\Desktop\CityGrows\common_fields\touchscreen_book_bookmark_ebook_icon_191190.ico"
However, when I run this executable file it says that there is no module named nltk.
Why is this the case?
As you are using the virtual environment, then activate the environment using conda activate citygrows_demo, and then install the conda install nltk.
But the question is python is itself an executable and the python code is interpreted. what is the executable common_fields_script.exe.
If you have written a python script in common_fields_script, save it as common_fields_script.py and run it using the python.exe which is created inside the virtual environment, in the terminal, something similar to below:
(citygrows_demo) C:/<path_where_your_scirpt_is>> python common_fields_script.py
I think that pyinstaller is missing a module when creating the executable.
To fix this, run pyi-makespec "C:\Users\lakna\OneDrive\Desktop\CityGrows\common_fields\common_fields_script.py" and then edit which modules it imports in the spec file.
There's a good example on how to do that here. In short you need to manually add the absolute path to the nltk package that conda installed in the datas section of the .spec file that the above command creates.
Once you've done that, run pyinstaller common_fields_spec.spec "C:\Users\lakna\OneDrive\Desktop\CityGrows\common_fields\common_fields_script.py"

How to specify Python version and library versions for PyInstaller executable

When creating an executable file using PyInstaller, how can I bundle a specific Python interpreter and some library from specific versions?
I want to create an executable file from my .py script. My __main__.py downloads some data from a website and transform them, then saves them in a folder as excel files.
And here are requirements.
Use Python 3.6
For this, I found some related posts but never clear to me. My main.py needs Python3.6 to be executed, and the users of this .exe file won't necessarily have Python3.6, so I want to bundle this Python in the .exe file as well. But is just a single command python3 -m pyinstaller __main__.py really enough? I'm not confident and I want to know what exactly I need to do.
Use specific versions of libraries such as pandas==0.23, beautifulsoup4==4.9.1 etc.
I think I need to work with pure in .spec file as the documentation says "pure: pure python modules needed by the scripts". But I cannot find any documentation about what exactly I need to do make it include pandas==0.23, beautifulsoup4==4.9.1 etc.
Any help would be appreciated!
I do this using virtual environments: if you have an environment with the desired Python version and package versions, you can pip install PyInstaller there and build the .EXE from that environment.
The Conda version would be:
Create the environment:
conda create --name my_env_name python=3.6
Activate it:
conda activate my_env_name
Install your desired package versions and PyInstaller:
pip install pandas==0.23
pip install beautifulsoup4==4.9.1
pip install pyinstaller
# or to get the developer version, which fixes some issues I have run into
# pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
And then build your EXE:
python pyinstaller myscript.py
Having this virtual environment can be a nice control as well for writing/testing your program, as it ensures no other dependencies are needed. Because of this, I tend to only install the necessary packages for the script into the environment.
However, I am not sure how one would do this with venv, if you do not have Anaconda. But maybe this will still point you in a direction (or someone else can elaborate? also see this post).

How do you install modules through Windows cmd if you installed Python though Anaconda?

When I use Windows cmd to install a Python module through pip or perform any other pip task I get the following error message:
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
I know I can use Anaconda prompt, but doesn't that reduce functionality? Isn't it better to use Windows cmd prompt?
I am using Windows 10 and I am following the path to the Scripts folder in Anaconda
If you want to use the Anaconda stack - and pip.exe is a part of it - you first need to activate it.
Anaconda3\condabin\activate.bat
This adds the following folders to the path and actually increases functionality.
Anaconda3\
Anaconda3\Library\mingw-w64\bin
Anaconda3\Library\usr\bin
Anaconda3\Library\bin
Anaconda3\Scripts
Anaconda3\bin
Some packages can only be installed with pip, but it's best practice to use a separate virtual environment for that, not the base environment.

virtualenvwrapper not installing correctly?

I am trying to use a Python virtual environment for the first time while trying to learn Django. I am using the instructions here. As I am using git bash on Windows, I am following the setup instructions for Windows.
I installed virtualenvwrapper using
pip3 install virtualenvwrapper-win
Now the command mkvirtualenv gets me bash: mkvirtualenv: command not found
I tried the solutions here to no avail.
pip3 list shows that the package is, in fact, installed, but there is no virtualenvwrapper (or virtualenv) .sh files in the site-packages directory, and the only related file I can find is virtualenvwrapper_win-1.2.5-py3.6.egg-info in an AppData/Roaming directory.
Any suggestions? Thanks.
I had the same problem and tried uninstalling virtualenvwrapper-win, just to see the list of files that would be removed. I saw that the mkvirtualenv was located in C:\Python\Python37\Scripts.
I noticed I was using the 64bit version of python (C:\Python\Python37\) alongside the 32bit one (C:\Python\Python37-32\), both folders being in the PATH of my system's properties. I removed the 32bit version's directories from the PATH and this seemed to work.
PS: I also noticed that running the commands from the MINGW terminal requires them to also have the .bat extension added:

Anaconda pip vs native Ubuntu pip

I have an installation of Ubuntu 14.04, which comes with Python 2.7 by default. If I were to install a Python package "foo", I would normally run pip install foo. The pip executable is found in /usr/bin.
However, I have now installed Anaconda, and I want to use this as my default Python interpreter. This means that when I run pip install foo, I want it to call Anaconda's pip, rather than the pip that comes with Ubuntu. In this way, installing a new package will copy it to Anaconda's site-packages directory, rather than that of the native Python installation.
Now, in my .bashrc file, I added export PATH=/home/karnivaurus/Libraries/Anaconda/bin:$PATH, and in that path is Anaconda's pip. However, this means there now exist two pip executables on PATH. How can I ensure that one which is called is that within the Anaconda distribution?
How can I ensure that one which is called is that within the Anaconda distribution
Executables on the PATH are inspected from left-to-right.
PATH=/home/karnivaurus/Libraries/Anaconda/bin:$PATH
Will now always use the Anaconda binaries if present.
If you would like to use the native pip, then you will need to qualify its path like so
/usr/bin/pip --version

Categories