General pip commands with Visual Studio - python

I'm currently trying to get my python project into an executable. I installed pyinstaller via the python environments on Visual studio:
and ran the command via this line:
Despite having found how to install packages using pip in this environment, I have not found how to actually run package commands. For example, I am trying to run the following pip command to generate an executable of my file:
pyinstaller --onefile --windowed database.py
Am I missing something here? Where do I do this?
(ps, I have git bash. Because I installed Python via Visual Studio, I cannot run pip or packages on my general bash shell)

Related

Vscode cant find my installed pip libraries. How can i get my pip libraries used in vscode on linux mint?

I am on Linux Mint. When i try to import robot for robotframework in my python application it doesnt get recognized as a installed library. This while i checked the executable with the "which" command.
which python
Gives the output: /usr/bin/python
I put that path '/usr/bin/python' in the interpreter path in vscode. But it doesn't get
the installed libraries.
when i use the terminal outside of vscode and do
pip list
I get a big list with all of my installed libraries. But when i do the same in VScode i just get a short list with nothing of the installed libraries.
I tried to deinstall python, vscode and reinstall both but that doesn't work. The python path to the system python.exe is in the PATH variables. I dont know what i can try further.
It looks like that they both point to the same pip instance but it doesn't recognize the same packages. Like it cant find the site-packages folder
Can anyone please help?
I've found the problem.
In Linux Mint when you install visual studio code via the application manager built into the OS. It installs the flatpack version of Visual studio code. Which creates what looks like its own environment that cannot get the pip packages from the main system.
For me what solved it was to download the .deb version from the official vscode website(https://code.visualstudio.com/Download) and install that one using the:
sudo apt install /Downloads/{name of downloaded.deb file}
When I used this version of Visual studio code it all worked for me with no problem.

Executable file doesn't run on Windows even with the .exe extension [duplicate]

I have a Python script that I'd like to compile into a Windows executable. Now, py2exe works fine from Windows, but I'd like to be able to run this from Linux. I do have Windows on my development machine, but Linux is my primary dev platform and I'm getting kind of sick of rebooting into Windows just to create the .exe. Nor do I want to have to buy a second Windows license to run in a virtual machine such as VirtualBox. Any ideas?
PS: I am aware that py2exe doesn't exactly compile the python file as much as package your script with the Python interpreter. But either way, the result is that you don't need Python installed to run the script.
As mentioned by other answerers, the cross-compilation feature is removed from PyInstaller since 1.5. Here, show how to package a Windows executable from Python scripts using PyInstaller under wine.
Step 1: Install wine and Python
sudo apt-get install wine
wine msiexec /i python-2.7.10.msi /L*v log.txt
PS:
Newer Python versions already include pip (is used to install pyinstaller). Download Python installation package from here (e.g., python-2.7.10.msi)
For macos users, use brew cask install xquartz wine-stable.
Step 2: Install PyInstaller on wine
$ cd ~/.wine/drive_c/Python27
$ wine python.exe Scripts/pip.exe install pyinstaller
Successfully installed pyinstaller-3.1.1 pypiwin32-219
Step 3: Package Python scripts
Package Python scripts (e.g., HelloWorld.py) with pyinstaller.
$ wine ~/.wine/drive_c/Python27/Scripts/pyinstaller.exe --onefile HelloWorld.py
# filename: HelloWorld.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
print('Hello World!')
The Windows executable file is located in dist/.
$ wine dist/HelloWorld.exe
Hello World!
fixme:msvcrt:__clean_type_info_names_internal (0x1e24e5b8) stub
Refer to here for the detailed description.
Did you look at PyInstaller?
It seems that versions through 1.4 support cross-compilation (support was removed in 1.5+). See this answer for how to do it with PyInstaller 1.5+ under Wine.
Documentation says:
Add support for cross-compilation: PyInstaller is now able to build Windows executables when running under Linux. See documentation for more details.
I didn't try it myself.
I hope it helps
You could run Windows in VirtualBox in order to run py2exe. VBox offers a powerful command-line client for automating tasks, so it something that you could likely integrate into your development process with ease.
Tested on Platform: Kubuntu 20.04, wine 6.0, python38
Download wine and python
Download windows version of python from https://www.python.org/downloads/release/python-3810/
Install wine
sudo apt install wine
Open your terminal and run
wine the-python-exe-you-downloaded
Run
find ~/.wine -name pip.exe
this will give you the pip path:
/home/yourusername/.wine/drive_c/users/yourusername/Local Settings/Application Data/Programs/Python/Python38/Scripts/pip.exe
Install pyinstaller
Run wine /home/yourusername/.wine/drive_c/users/yourusername/Local\ Settings/Application\ Data/Programs/Python/Python38/Scripts/pip.exe install pyinstaller
Package your file
Find installation path
find ~/.wine -name pyinstaller.exe
wine /home/yourusernmae/.wine/drive_c/users/yourusername/Local\ Settings/Application\ Data/Programs/Python/Python38/Scripts/pyinstaller.exe --onefile yourpythonfile
I wrote a blog post on how to do this with PyInstaller. Here's the summary:
How to create EXEs for Python on Linux, using PyInstaller and WINE
Download Python 3.8 Windows installer
wine python-3.8.9.exe, then see instructions below
wine C:/Python38/python.exe -m pip install --upgrade pip
wine C:/Python38/python.exe -m pip install -r requirements.txt, and requirements.txt should include PyInstaller itself
wine C:/Python38/Scripts/pyinstaller.exe ...
All done!
Installing Python 3.8 in Wine:
Check "Add Python 3.8 to PATH"
Click "Customize installation
Click "Next"
Click "Install for all users"
Set the install location as C:\\Python38
Click "Install"
Close the window.
Feel free to read the post to get more details.
I have tested py2exe inside of wine, and it does function. You'll need to install python in wine for it to work, or if you only use the standard libarary, you can bundle py2exe with py2exe from the windows machine and then use it in wine. Just keep in mind you need the same version of the ms visual C libraries in wine as were used to compile python or things won't work properly.

visual studio code-should I install python in virtual environment in the folder of my project?

I have set up my virtual environment in a project folder on my desktop, I also used pip install to install django 2.2 in this project folder on my desktop. I have python installed, but it is in another folder elsewhere on my computer, do I need to install python in the same project folder on my desktop? I am getting messages in virtual studio, which say, "visual studio code, workspace contains pipfile but 'pipenv' was not found". Also when try to use pip install to install python into the project folder on my desktop I get an error message in terminal(I am using a mac) which says,
pip install python3.8
ERROR: Could not find a version that satisfies the requirement python3.8 (from versions: none)
ERROR: No matching distribution found for python3.8
I'm also getting error messages which say:
visual studio code no python interpreter is selected
&
there is no pip installer available in the selected environment
So overall, do I need to install python in the project folder and if so, how do I do this? Do i need to install the python interpreter as well? I have had a problem with bash wherein have to type:
PATH=/Users/aleong/opt/anaconda3/bin:$PATH
to create my virtual environment, I'm not sure if this is why python won't install, however I did type this into my terminal initially..
plz help, thank you
Well, from the error message you get about Pipfile, it means that you need to install pipenv which is by itself a virtual environment. After installing it go to your project and type this pipenv shell this should activate your virtual env and then type this pipenv install this should install all dependencies from Pipfile.

Trouble importing third party Python packages to GIMP 2.10 so that they can be used to write GIMP plugins

My goal is to import a couple third party Python packages for use with my GIMP installation. This will allow me to use these packages when developing a GIMP plugin. I noticed a few directories that may be of use. They are as follows:
C:\Program Files\GIMP 2\32\lib\python2.7
This directory contains a site-packages folder which contains packages such as requests and pip.
C:\Program Files\GIMP 2\32\bin
This directory contains a python.exe. When I run python --version in an elevated cmd at this directory path, the output is Python 2.7.16, which I assume is GIMP 2.10's version of Python. This is important because I have my own installation of Python 3.8.0 in my Program Files. If I'm anywhere outside of this path in the cmd, the version that outputs is 3.8.0.
I have added these directories to my PATH system variable and tried running pip install but the output tells me I have already installed the requested third party packages. The problem is that they are installed to my Python 3.8.0 installation. I'm trying to run pip install in the context of GIMP's Python environment.
Any advice would be much appreciated.
Grab get-pip.py here
Put it into your GIMP Python directory (C:\Program Files\GIMP 2\Python)
From a Windows Command Prompt Window cd to that directory
Run get-pip with this python instance: .\python.exe get-pip.py. You now have pip installed in the GIMP version of Python.
You can now use this pip instance with Gimp's Python runtime: .\python.exe -m pip install --user <package>
Uplifted/adapted from here
Turns out the package I was trying install had dependencies that required a higher version of Python than the one GIMP comes with. Thanks to those whom responded.

python pip install not working on windows

I have python 2.7.10 installed on windows and I am trying to install Django on the commandline with the following command:
C:/users/user/myproject> python pip install django
This displays the following error:
python: can't open file 'pip' [Errno 2] No such file or directory
Python is installed in C:\Python27 and the PATH environment variable is also set to that.
Why is pip not working?
Since Python 2.7.9 pip is included when python is installed.
However the scripts subfolder of your python installation might not be added to your PATH environment variable, and hence inaccessible by just typing pip install. However as long as your python executable is on the path, you can use the python -m flag to execute the pip module as a script:
python -m pip install SomePackage
This should work from the command line as long as python is on PATH.
If you would like to use pip directly from the cmd.exe prompt you need to add the scripts directory to your PATH environment variable:
SET PATH=%PATH%;C:\Python27\scripts
Some times in windows it especially needs Microsoft visual c++ compiler. If such error persists you can verify the log file and If needed you can download here
http://aka.ms/vcpython27

Categories