Ensure pyinstaller run with Python 2.7 - python

I've a Python project, run it on Ubuntu 18.04 server machine (in VBox). I've created 2 venvs:
* virtualenv -p /usr/bin/python2.7 venv27
* virtualenv -p /usr/bin/python3.6 venv36
Start venv27 with command:
source path/to/my/venv/python/venvs/venv27/bin/activate
After venv starts to run I've installed PyInstaller with:
pip install pyinstaller
Generation process was sucesfully done, but during the generation process I've seen this message:
46 INFO: Python: 3.6.8
Does it means that PyInstaller run with Python 3.6 however I run PyInstaller in venv where python version is 2.7?
I would like just be ensure that my compressed python code use python 2.7?
Thanks for your help and answer!
I've delete all created venvs and start it again. Here is the results:
Activate the new venv27:
Installed again PyInstaller:
...and now the message was:
Currently I've not created venv36 only venv27, so probably problem could be, but I am not sure that venv36 was active, but I didn't know that.
Thank you Gantemens for your help. My last question is: how can I accept your answer/suggestion because it looks like both comment were right.

Related

PyInstaller error loading Python DLL when running executable on another machine

I'm trying to run a pyinstaller-built executable on another machine. The error I see is Error loading Python DLL 'C:\Users\User\AppData\Local\Temp\_MEI70722\python39.dll
I built the program like this, I also added -F to make sure the executable is standalone:
py -m PyInstaller script.py -F
I tried adding --add-binary and --add-data options with the path to python39.dll, but that didn't help.
The program is built on Windows 10 x64, the machine I'm trying to run the program on is Windows 7 x64. Even with such a difference and the fact that Python 3.9 is not for Windows 7, I really doubt this is the reason, otherwise I would expect another error.
What am I doing wrong?
Ok so here's solution that worked for me:
Install a Windows7-compatible version of python3. I did this from the Windows Store, which made it accessible in my command line as "python3."
Set up a virtual environment with your downgraded version of python. On command line, that's
...> python3 -m venv my_env
In command line, navigate to your newly created environment directory, and use pip to re-install pyinstaller in your new environment:
...> cd my_env
...\my_env> pip install pyinstaller
From command line in my_env, use pyinstaller to compile your code. You should probably move script.py into your my_env directory.
...\my_env> pyinstaller script.py -F
I was able to copy the standalone script created in \my_env onto a Windows 7 machine and run it successfully. Hope this helps!

Python virutalenv does nothing

I am trying to run a simple python virtual environment and for some reason, nothing happens when I run a command. I open a new folder, cd into it, and run: python3 -m venv tutorial-env followed by source tutorial-env/bin/activate. All that happens is a new line is returned, but I am missing the (tutorial-env) at the beginning, and I am not in the virtual environment. Does anyone have an idea of how to fix this?
Some helpful info:
I'm on a mac
python3 --version returns Python 3.9.5
which python returns usr/local/bin/python3

Anaconda Python: ModuleNotFoundError: No module named 'matlab'

I'm new to Python and Linux and want to install a MATLAB Engine for Python 3.6. I already followed the steps from Mathworks (http://www.mathworks.com/help/matlab/matlab-engine-for-python.html)
and tried also to use python setup.py build --build-base=$(mktemp -d) install but the error still appears. I have MATLAB R2018a installed and use Spyder 3.2.8 with Anaconda.
Does someone has an advice?
Thanks in advance!
If you're trying to install matlab engine in a conda environment, follow the below steps:
cd "matlabroot\extern\engines\python"
python setup.py install --prefix="installdir"
Eg
cd /opt/MATLAB/R2019a/extern/engines/python
python setup.py install --prefix="/home/nagabhushan/anaconda3/"
Now, matlab engine package is actually installed under the separate
anaconda3/lib/python3.6/site-package/matlab
So you need to manually move that matlab folder to the site-package folder your python is using. If you have multiple virtual envs, move it to the corresponding site-package folder of the virtual env you will run program.
Eg
anaconda3/envs/my_env/lob/python3.6/site-packages/matlab
References:
https://stackoverflow.com/a/41800724/3337089
https://stackoverflow.com/a/56553740/3337089
Edit 1 (03-Mar-2020):
I tried activating my environment and then simply installing matlab engine and it worked! I'm using Python 3.7
python setup.py install
Note that this initially gave error that error: You do not have write permission in build/lib/matlab/engine/, but changing the permission of build directory recursively worked: sudo chmod -R 777 build/
Following Nagabhushan S N answer,here, in order to install matlab/matlab.engine with conda (miniconda3) with Linux Ubuntu 18 LTS and Matlab 2018, I performed the following steps.
I have created a new conda enviroment (python36) with Python 3.6 interpreter, Python 3.6 is one of the supported version by Matlab 2018 (and you need to match the right Pyhton version or it'll install Python 2.7 libs), and I have directly installed the libs in the python36 env subfolder, in detail:
cd /usr/local/MATLAB/R2018a/extern/engines/python
python setup.py install --prefix="/home/myname/miniconda3/envs/python36"
e.g., import matlab.engine is now usable from the python36 environment.
P.s: the installation needs write access to the build subfolder (under usr/local...), so you need to go sudo and chmod -R +777 /usr/local/MATLAB/R2018a/extern/engines/python/build
P.s.2: by installing only in a base env, in my case, does not provide matlab.engine to work with the other conda envs too.. perhaps this is a normal, expected, conda behaviour.
After many tests I think I solved the problem. I will post the answer if someone has the same problems. As mentioned here:
https://stackoverflow.com/a/39759581/9834571
You can add an alternative python command. For me it worked when I vary the mentioned example as followed:
sudo update-alternatives --install /usr/bin/python python ~/anaconda3/envs/ 2
update-alternatives --display python
cd /usr/local/MATLAB/R2018a/extern/engines/python/
python setup.py build --build-base=$(mktemp -d) install

How can i switch python version, that runs by command "python" in UBUNTU 14.04

This morning i wanted to host my Discord Bot, written on Python on my VPS on Ubuntu 14.04 After couple of minutes f##$ing with Python repos i realized, that i got several Python versions installed on my VPS.
The main one is Python 2.7.12, that is absolutely old and can't launch Discord Bot, cause it needs pip install Discord, that is supported only with Python 3 and upper. After couple of minutes I installed Python 3.6.3, that i needed. But when I tried to install Discord for Python it didn't install, because it needs, as I've said, Python 3 and upper version. I saw in cmd, that while installing this Discord Plugin for Python cmd tried to execute command python setup.py egg_info, that failed because python runs Python 2.7.12 and to run Python 3.6.3 I've installed i need to write python3.6. So, how can i switch the default (main) version of Python in order to run Python 3.6.3, while executing python.
Thank you for your answers. (My apologize, if I've exploded your brain)
It is not recommended to change default python.
You just type 'python3'
$ python3 yourscript.py
Or take a look at this Two versions of python on linux. how to make 2.7 the default
Windows
To run Python2.x
py -2 script.py
To run Python 3.x
py -3 script.py
On Linux use :-
python3 script.py

Ubuntu 16.04 default python environment in my user profile is Anaconda Python2, unable to run guake "anaconda2/bin/python2: No module named guake"

I recently installed Ubuntu 16.04 and for ease of developing Machine Learning and other AI programs using Python2, I installed the Anaconda Python2 full distribution.
I always use 'guake' terminal emulator which I find best for productivity. So I installed Guake in my Ubuntu and when I try to run it, I get the following error:
/home/enlighter/anaconda2/bin/python2: No module named guake
I deleted all *.pyc files in /usr/lib/python2.7/dist-packages/guake/ folder, but that didn't help.
I am guessing this is an python environment issue. The /usr/bin/guake script contains only these rwo lines:
PYTHON="/usr/bin/env python2"
exec $PYTHON -m guake.main "$#"
Can anybody please tell me how to resolve this?
you don't execute the right Python execute: /home/enlighter/anaconda2/bin/python2 while you installed in /usr/lib/python2.7/dist-packages/guake/.
Use /usr/bin/python2 as default interpreter or install in /home/enlighter/anaconda2/lib/python2.7/dist-packages/guake/.
To install within anaconda python environment, clone the guake github repository and then build and install guake.

Categories

Resources