Executable file in venv\Scripts not recognised as a command - python

I have cloned a github repository - pypastry - onto my Windows machine, and run pip install -e pypastry to install it in my virtual environment, so the project structure is like this:
│-- pypastry
|-- venv
|-- Scripts
|-- pastry
The executable file, called 'pastry', is sitting in venv\Scripts as I would expect, but Command Prompt isn't recognising it, and I am receiving the error:
'pastry' is not recognized as an internal or external command, operable program or batch file
I don't think it's a problem with PATH as the first item in PATH is C:\Users\User\Documents\pypastry\venv\Scripts.
This is the executable file itself:
#!c:\users\user\documents\pypastry\venv\scripts\python.exe
# EASY-INSTALL-DEV-SCRIPT: 'pypastry==0.0.1','pastry'
__requires__ = 'pypastry==0.0.1'
__import__('pkg_resources').require('pypastry==0.0.1')
__file__ = 'C:\\Users\\User\\Documents\\pypastry\\pypastry\\pastry'
with open(__file__) as f:
exec(compile(f.read(), __file__, 'exec'))
Can anyone spot anything in this file which might mean it's not recognised as an executable on Windows or think of anything else that could be going wrong?
EDIT TO ADD:
If I run the file with the explicit python invocation (python pypastry\pastry) it works, but I don't want to have to do this as it creates other issues.

Windows is telling you that it does not find an executable called "pastry" (pastry.exe, pastry.com, pastry.bat, pastry.cmd ...) on your PATH.
But pastry.py is. Isn't it? The problem is that your windows is not configured to recognize .py as an executable extension.
To run python scripts in Windows without the explicit invocation of python.exe, you need first to have the .py extension associated to the executable python. And then the .py extension added as an executable extension.
You do so in three steps:
Associate the .py extension to a PythonFile file type
ASSOC .py=PythonFile
Associate the PythonFile to your python.exe executable
FTYPE PythonFile="c:\users\user\documents\pypastry\venv\scripts\python.exe" "%1" %*
Associate the .py file extension as one of the default executable extensions
SET PATHEXT=.py;%PATHEXT%

Related

After compiling a python script to EXE the Archive method doesn't work

I have a python script that I compiled to an EXE, one of the purposes of it is to extract a 7z file and save it to a destination.
If I'm running it from PyCharm everything works great, this is the code:
def delete_old_version_rename_new(self):
winutils.delete(self.old_version)
print("Extracting...")
Archive(f"{self.new_version}_0.7z").extractall(f"{self.destination}")
print("Finished")
os.rename(self.new_version, self.new_name)
I used pyinstaller to compile the program and used to command pyinstaller --onefile --paths {path to site packages} main.py
Thanks!
Single-file executables self-extract to a temporary folder and run from there, so any relative paths will be relative to that folder not the location of executable you originally ran.
My solution is a code snippet such as this:
if getattr(sys, 'frozen', False):
app_path = os.path.dirname(sys.executable)
else:
app_path = os.path.dirname(os.path.abspath(__file__))
which gives you the location of the executable in the single-file executable case or the location of the script in the case of running from source.
See the PyInstaller documentation here.
Eventually i just used a 7z command line i took from https://superuser.com/questions/95902/7-zip-and-unzipping-from-command-line
and used os.system() to initialize it.
Since my program is command line based it worked even better since its providing a status on the extraction process.
Only downside is i have to move the 7z.exe to the directory of my program.

script is on PATH, yet python3 script fails: no such file or directory

dag#Arokh:~$ source /home/dag/.bashrc
dag#Arokh:~$ echo $PATH
/home/dag/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
dag#Arokh:~$ python3 /home/dag/.local/bin/facemorpher --version
Face Morpher 1.0
dag#Arokh:~$ python3 facemorpher --version
python3: can't open file 'facemorpher': [Errno 2] No such file or directory
Adding the directory to PATH doesn't seem to help. How can I make python3 facemorpher work from any directory?
python3 pays no attention to the PATH variable when looking for scripts. This variable controls where the shell looks for executables.
So what should work now, provided the script has executable permissions and a valid shebang like #!/usr/bin/env python3 as its very first line, is that simply
facemorpher
without python3 in front should run the script. Perhaps this is actually what you want and need.
The python3 command without any options expects a file name parameter; there is no simple way to make it look for a file which doesn't exist in the specified directory (which is the current working directory if the filename doesn't have an explicit directory part; this is how the operating system resolves relative file names, and should probably not be messed with for an individual command). For further details about this, perhaps see also Difference between ./ and ~/
For the record, chmod a+x path/to/scriptname adds execute permission to the script for all users on the system, and the path in the shebang after #! should point to your Python interpreter's full path, or the full path to a utility like env which finds it on your PATH and executes it based on just the command name (here, python3; but on some systems, the Python interpreter executable's file name is just python, or more broadly whatever the system's owner decided to name it).

Can not run exe packed by pyinstaller

I use windows 10 and python2.7.
I have use PyInstaller to pack a program into exe. But I can not run the .exe file.
error:
raise FileNotFoundError('Tcl data directory "%s" not found.' % (tcldir))
IOError: Tcl data directory "C:\Users\test\AppData\Local\Temp\_MEI10~1\tcl" not
found.
[4072] Failed to execute script pyi_rth__tkinter
That's python error which means your program is running.
Check your code to see why it does not find the file you are mentioning.
Note: If you use relative paths consider that it matters where the .exe file is executed.
This is the process home directory.
You should use the following command:
pyinstaller main.py --add-data 'tcl;./tcl' #linux separator use 'tcl:./tcl'
Note: left 'tcl' is in the main.py's directory, right 'tcl' is target directory which is exe genrated directory. if right 'tcl' not existing will be created!

PyInstaller UAC not working in onefile mode

Hello everybody.
I have a small python project and want to make it to single executable file. I am using...
Windows 7
Python 3.4
PyInstaller 3.2.1
My PyInstaller command is,
PyInstaller -y -w -F -n output_file_name --uac-admin --clean source_file.py
this command works properly. But single output file does not ask for admin rights when executed. And there's no shield mark on executable file icon.
When remove the -F option (equivalent to --onefile), output executable file has shield mark on its icon and ask me admin rights. But this is not what I want. I want a single executable file.
I found a manifest file (output_file_name.exe.manifest) in dist\output_file_name folder. So I did...
PyInstaller -y -w -F -n output_file_name --manifest output_file_name.exe.manifest --uac-admin --clean source_file.py
But this command doesn't work. Its single executable file still does not ask for admin rights.
I have removed PyInstaller and installed recent development version.
pip install git+https://github.com/pyinstaller/pyinstaller.git#develop
But the result is same. Its output doesn't have a shield mark on icon and does not ask admin rights.
Do you have any idea?
Please help me!
I found what's wrong!
The key point is...
Install PyInstaller 3.0
Manifest file must be located in dist folder where single excutable file located
The name of manifest file must be same as output file.
If manifest file is located in dist folder, no need to specify --manifest option. --uac-admin is enough.
You can find manifest file at build folder.
Thank you.
Adding up passion053's answer, in my case I used -F instead of --onefile and it works fine for me but yeah you need to add manifest file in the same directory as your single executable.
Note: I used pyinstaller version 3.5. and it works fine for my
Happy Coding!
Adding -r prog.exe.manifest,1 to pyinstaller command line worked for me, after that no need for putting manifest file near exe, pure single exe file.

how do i get windows to execute .py with specific `python.exe`?

i tried in Control Panel\Programs\Default Programs\Set Associations, and also assoc/ftype, but windows keeps using the wrong python.exe (C:\Python27\) instead of the one i want (C:\Users\nlab\Downloads\WinPython-64bit-2.7.9.5\python-2.7.9.amd64\)
>where python
C:\Users\nlab\Downloads\WinPython-64bit-2.7.9.5\python-2.7.9.amd64\python.exe
C:\Python27\python.exe
C:\Program Files (x86)\LilyPond\usr\bin\python.exe
>assoc .py
.py=Python.File.WinPython
>ftype Python.File.WinPython
Python.File.WinPython=C:\Users\nlab\Downloads\WinPython-64bit-2.7.9.5\python-2.7
.9.amd64\python.exe "%1" %*
>set PATH
Path=C:\Users\nlab\Downloads\WinPython-64bit-2.7.9.5\python-2.7.9.amd64;...C:\Python27;C:\Python27\Scripts;...C:\Program Files (x86)\LilyPond\usr\bin;...
PATHEXT=.PY;...
i just made up Python.File.WinPython, is that allowed?
https://github.com/winpython/winpython/wiki/Installation#Registration
(but you will loose your python2.7 registration if you do that)
the other solution is :
call C:\Users\nlab\Downloads\WinPython-64bit-2.7.9.5\scripts\env.bat
python my_progam_.py

Categories

Resources