Error packaging program in py2app - python

I have a program written in python 3.3 that I'd like to be able to distribute without the need for users to install python or any additional modules. I was able to successfully package this program using cx_Freeze on Windows, but the same script on OS X produced an app that wouldn't launch.
I thought I might have better luck using py2app, but now I'm running into a strange problem. The program opens (it has a GUI built with tkinter) and runs flawlessly when built in Alias mode. When I attempt to construct a final build, however, I get the following message in Terminal:
error: No such file or directory: /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/setuptools-2.1-py3.3.egg/_markerlib/__init__.pyc
I navigated to that directory and found a .egg file that I'm unable to open or extract. I've tried reinstalling setup tools and well as python itself with no luck. Has anyone experienced this problem?

It looks like the problem is that your setuptools is somehow broken.
To open the egg file, I tried downloading a third party tool, which crashed, and renaming it as a .zip, which failed. If I just double click on it, I get the "choose default application" popup.
Double-clicking it relies on the extension to decide what app to launch.
The best way to check whether something is a valid zip file is to use the unzip tool from the command line. For example:
$ unzip -t setuptools.egg
This will check all of the zip headers, and check the CRC of all files in the archive, and report any errors. Or, if it's not a zip at all, it'll report one error right at the start.
You can also use the file command to do a quick check to see whether it's some well-known type of file. If file /path/to/setuptools-whatever.egg just says "data" instead of "Zip archive data", then it's probably corrupted beyond recognition.
Anyway, assuming your setuptools didn't come with your Python installation (if you're using a python.org binary installer, it didn't), the safest thing to do is uninstall it, then reinstall it cleanly.
The reason it's important to uninstall first is that the current version will, by default, not install a .egg archive, but will instead install a normal unzipped package and egg-info directory, meaning it may not overwrite the old, broken copy.
The documentation covers uninstalling. Just delete the setuptools .egg file, and anything else named setuptools*, from your site-packages (and anywhere else on your sys.path). If you have distribute there as well, kill that too. This will leave a few files sitting around in other places (notably easy_install-3.3 somewhere on your PATH), but they'll get overwritten properly by the installation, so that's OK.
To install, just follow the usual instructions to reinstall it:
$ wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | python
… or, if you don't have write access to site-packages:
$ wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | sudo python
If you use pip, you may want to reinstall it after reinstalling setuptools, and then pip install -U setuptools pip just to make sure you have the latest versions—and to verify that everything is now working.

Related

Bundling a Kivy/Python App into an easily installable .app file for mac

I have been writing a graphical data management app in Python/Kivy for MacOS, and when I am done, I would like the end user to be able to install it without touching the command line. The computers that it is intended for already have python, but not Kivy. I was wondering what the easiest approach would be, perhaps an installer that would just execute 'pip install kivy' in the command line, or a python file using the OS module that installs it, or maybe pyinstaller. Thanks!
This is actually mentioned in the Kivy documentation here. Read more for customizing your install.
Prerequisites
For a basic install, you first need to install PyInstaller and Cython. Do this with pip3 install PyInstaller, Cython.
Bugs
There is a bug in setuptools that causes PyInstaller to not work. You need to have a version of setuptools less than 45.0.0 to work. To do this, run the following command pip3 install --upgrade setuptools==44.1.1. Finally, you are ready to package
Creating *.spec file
PyInstaller works off of a *.spec file. To create this, as said by the Kivy documentation, run the following command:
pyinstaller -y --clean --windowed --name <the name of the *.app> \
--exclude-module _tkinter \
--exclude-module Tkinter \
--exclude-module enchant \
--exclude-module twisted \
/path/to/main/program.py
Remember to replace <the name of the *.app> with what you want the name of the *.app to be, and /path/to/main/program.py with the path to your main python program file. The path can be relative too. This will take a bit, but will produce a file with an extension of a *.spec, which you will use to customize the app, create a directory called build, which you can delete, and create a directory called dist. Inside the dist directory, you will find your application.
Debugging
If when you open your app it immediately closes, you have an error. To find out what it is, find the app in Finder, right-click it, and select "Show Package Contents```. Go inside a folder called "Contents", then inside a folder called "MacOS", in which you will see a lot of files. Find a file with a little "exec" icon on it with the name of the *.app file. Double-click this. This will bring up a terminal window with errors and console output. Copy-paste the error into Google, which should help, and also feel free to comment it here, and I will try to check it out!

SCons does not seem to install (Windows)

I have been trying for hours to install SCons on my Windows 8.1 machine and simply cannot. I honestly have no idea whatsoever what I'm doing wrong, or really what I'm doing in general. Here is the step by step process of what I have done
1: installed Python 3.7 from www.python.org I used the python-3.7.3-amd64.exe to install it, it seems to have worked (I have never used python before so if anything is off I wouldn't realize it). When I use the command console and input 'python --version' it outputs 'Python 3.7.3'
2: I downloaded scons-3.0.5.zip from www.scons.org I followed the website's instructions as best I could. I used 7zip to extract it's contents into a new file called 'scons-3.0.5' located at C:\ It's complete path, therefore, is C:\scons-3.0.5
3: I ran Python 3.7 as an admin. I inputted '# cd scons-3.0.5' just as the scons website says to do. It outputted nothing, and I noticed that the new line started with '...' instead of '>>>', I have no previous experience with Python so I don't know if that's good or bad. I then continued to follow the instructions by inputting '# python setup.py install', it outputted nothing, and once more the new line started with '...'. I hoped that was all I needed to do but in the command console I inputted 'scons --version' (I read somewhere this can be done to check if it is installed), it outputs "'scons' is not recognized as an internal or external command, operable program, or batch file.". This, combined with the fact that seemingly nothing is different, leads me to believe it has not been installed.
4: I tried to do something a bit different. I noticed that the zipped file I downloaded from the scons website contained 2 files in it, 1 being scons-3.0.5, the other being pywin32-master.zip, I had both of these in the file C:\scons-3.0.5 I decided to delete that file, and in its same location place the scons-3.0.5 file. Now instead of C:\scons-3.0.5 including scons-3.0.5 and pywin32-master.zip it contained just the contents of the scons-3.0.5 file that was in it before (if that makes sense, I might clean it up in the morning and make it easier to read). I once more did step 3, and the results were no different.
I have no idea what I'm doing, I have no prior experience with Python or the command console, I just want to set up scons and never use Python again. Does anyone know how I can fix this? I have googled for hours but it seems as if I'm the only one who's having this issue.
The contents of the zipped file from scons website:
contents of the scons-3.0.5 file in the zipped file
I doubt the images will help but I have included them just in case if they seem off
edit: I did know what installing via Pip was, but I googled it and it worked just fine! Thanks to Alexander Lopatin and bdbaddog for the help
So you're mistake is in step 3.
I ran Python 3.7 as an admin. I inputted '# cd scons-3.0.5'
The website says:
# cd scons-3.0.5
# python setup.py install
Notice this is
cd into the unzipped directory
THEN run python setup.py install
Instead you've run python, then typed a shell command into python. Which is why you had issues.
Note: On windows you shouldn't need to run as admin to install SCons.
Although as #dirkbaechle said. Pip is the preferred method to install python.
python -mpip install scons
But if you'd rather follow the instructions. Just bring up a windows command shell, or powershell if you like, cd into the unzipped directory, and run python setup.py install
BTW. There's an IRC channel and a users mailing list for SCons support.
https://scons.org/contact.html

How to unzip .rar file with Python and patoolib

I need uncompress .rar file in Google Colab with Python3. First I tried to do localy in MacOS.
I have installed Patoolib package:
pip install patool
and unrar to unzip .rar files
brew install unrar
Then, In my python script I do:
import patoolib
patoolib.extract_archive("data_2/Peliculas.rar", outdir="/data_2")
and I get the following error :
PatoolError: could not find an executable program to extract format rar; candidates are (rar,unrar,7z),
I need to configure Patool to use unrar but there is no documentation available. Somebody knows how to solve this error?
My issue was solved by simply adding my Winrar directory to my Path (in system environment variables). Made the horrible mistake of assuming it was set up by default (because why wouldn't it, it's already on the contextual menus right?), but that was not the case.
Hope this helps whoever reads this

Installing a python package in a desired folder

I have downloaded a python package to install, on my ubuntu machine. The package has already a setup.py file to use, but I want to change the default python installation address to something else, for this package specifically (and not for good). So what I tried is:
First in the terminal, I export that address of the new folder:
export PYTHONPATH=${PYTHONPATH}:${HOME}/Documents/testfolder/lib/python2.7/site-packages
Then I add this exported address as prefix to the installation command:
python setup.py install --prefix=~/Documents/testfolder
The installation goes through. Now to make python always look for this new path as well (next to the default installation path), I export the address in bashrc file:
export PYTHONPATH="${PYTHONPATH}:~/Documents/testfolder/lib/python2.7/site-packages"
But now whenever I open a terminal and try to import the installed package, it cannot see ("no module named..."). Only when I open a terminal in the folder where I had the installation files (namely setup.py), and run python, can it then see the package, and it works there.
Why isn't my export in bashrc making the package available from anywhere?
Is there something I have done wrong in the above?
To answer your question about the export path. Do you have $PYTHONPATH as a part of your $PATH? If not you should add it to path.
The best way to handle this scenario in my opinion is to use a virtual python environment. There are a couple to choose from, but I like virtualenv the best. The reason to take this approach is because you can manage different versions of python in separate folders. And have separate packages installed in these folders. I recommend looking into it as it is a very useful tool. If you want an examole of how to use it i can provide that https://virtualenv.pypa.io/en/stable/

Python 3.4 and 2.7 installation no Script folder and no pip installed

I was doing a fresh installation for Python 2.7.9 and 3.4.3 on Win7 X64 today, and I found that there is no Script folder in Python27 and Python34 folder as first child level folder, but there is one in Tools. However, I couldn't find pip within that Script folder, although pip should be installed with Python by default. The other I was doing the same installation for my other PC and laptop, there was Script folder (as first level child folder in Python27 and Python34) containing pip. So what is going on? how to install pip and maybe other useful scripts this way?
[EDIT] I tried python -m ensurepip in Python34. I got the following errors:
Ignoring indexes: https://pypi.python.org/simple
Collecting setuptools
Exception:
Traceback (most recent call last):
File "C:\Users\daiyue\AppData\Local\Temp\tmppvmc8dv1\pip-6.0.8-py2.py3-none-
any.whl\pip\basecommand.py", line 232, in main
status = self.run(options, args)
File "C:\Users\daiyue\AppData\Local\Temp\tmppvmc8dv1\pip-6.0.8-py2.py3-none-
any.whl\pip\commands\install.py", line 339, in run
requirement_set.prepare_files(finder)
File "C:\Users\daiyue\AppData\Local\Temp\tmppvmc8dv1\pip-6.0.8-py2.py3-none-
any.whl\pip\req\req_set.py", line 333, in prepare_files
upgrade=self.upgrade,
File "C:\Users\daiyue\AppData\Local\Temp\tmppvmc8dv1\pip-6.0.8-py2.py3-none-
any.whl\pip\index.py", line 326, in find_requirement
file_locations, url_locations = self._sort_locations(locations)
File "C:\Users\daiyue\AppData\Local\Temp\tmppvmc8dv1\pip-6.0.8-py2.py3-none-
any.whl\pip\index.py", line 158, in _sort_locations
sort_path(os.path.join(path, item))
File "C:\Users\daiyue\AppData\Local\Temp\tmppvmc8dv1\pip-6.0.8-py2.py3-none-
any.whl\pip\index.py", line 139, in sort_path
if mimetypes.guess_type(url, strict=False)[0] == 'text/html':
File "C:\Python34\lib\mimetypes.py", line 287, in guess_type
init()
File "C:\Python34\lib\mimetypes.py", line 348, in init
db.read_windows_registry()
File "C:\Python34\lib\mimetypes.py", line 255, in read_windows_registry
with _winreg.OpenKey(hkcr, subkeyname) as subkey:
TypeError: OpenKey() argument 2 must be str without null characters or None, not str
[EDIT] The problem is due to multiple null Registry keys in HKEY_LOCAL_MACHINE that make read_windows_registry() in mimetypes.py searches failed. Here is the post that leads to the solution:
Python ‘pip’ and Windows registry corruption
thanks
If you used the PSF (python.org) .msi Windows installers, pip (and dependencies) should be installed in pythonxy/Lib/site-packages for 3.4.0+ and 2.7.9+. There should also be pythonxy/Scripts containing about 5 .exes. This is the last part of the install process. A command prompt window should briefly appear. Perhaps you did not have [ ] install pip checked when doing the installs (although this should have been checked by default). Perhaps there was an error that you missed.
In any case, you should have pythonxy/Lib/ensurepip/* present for both 2.7 and 3.4 and you should be able to run this module now. In Command Prompt, try python -m ensurepip in both .../python27 and .../python34.
Had the same issue, reinstalling didn't help.
Finally fixed it by running python -m ensurepip as administrator.
This problem is a official bug: Issue23604 .
I had encountered the same problem, and fixed it successfully using the method in
Swarley's Blog.
I ran into the same issue today while trying to install Python 2.7.13 in my computer; after some investigation I realized that v.3.60 ("Anaconda") was already present (it came along with Microsoft Visual Studio 2017, which I've installed a couple weeks ago).
I suspected of some path mismatch in the registry, so I tried removing both Python v. 3.60 and 2.17, and cleaning up the Registry by deleting the HKCU\Software\Python key (which, due to some reason, was still present).
After this, I was able to correctly install version 2.7.13, and this time the \scripts folder is present, with all the expected contents.
I don't know if installing v. 3.6 again would cause any problem: I'm not going to try this for the time since I'm currently developing for v.2.7.
Hope this can be of some help, anyway.
Max - Italy
EDIT:
I've made some further investigation and think I've discovered the reason why (in my case), the \Scripts folder was missing: the path where I was going to install Python is in virtual drive.
In my computer I only have one partition (C:), and i've mapped a folder (C:\Development) as D:, then I tried to install Python on D:\Python27; apparently this is not "good" and causes some problem in the installer.
After discovering that, I tried installing to the real path, and now everything seems to be OK.
Max.
Resolved by installing Python 2.7.13
https://www.python.org/downloads/release/python-2713/
Windows 10. I had this issue while installing Python 2.7 into C:/Program Files/Python27 .. I think in this case it was a path issue. Fix was to do an install into C:/Python27, copy the Scripts folder from that installation to the installation in C:/Program Files/Python27. Everything else (including the paths to Python and Scripts) was fine.
Based on a combination of whats here, and what I found elsewhere, here is how I fixed it:
Uninstall whatever is installed already.
Go to regedit and HKLM/SOFTWARE/Python and delete the whole python section.
Reinstall Python
This installed with the scripts folder this time.
Hope this helps someone.
Guess what? In case you have NetBeans (or probably GlassFish) installed, then it could break installation for pip!
Details: there's a bug in NetBeans installer that could sometimes break the Windows registry in a way that's not expected by other installers.
#J3soon's answer was close, but Swarley's blog post haven't fixed the problem in my environment, because it wasn't a null character but was another kind of registry corruption.
And here's how I got rid of the issue. Run the following PowerShell script:
$local_key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
$machine_key = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*'
$machine_key6432 = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
$items = Get-ChildItem #($local_key, $machine_key, $machine_key6432)
$ErrorActionPreference = 'Stop'
foreach ($item in $items) {
Write-Output $item.PSPath
$null = Get-ItemProperty $item.PSPath
}
It will write the registry key names to the output. In case it prints an error, take the one last key it printed and remove that from the registry (using PowerShell or regedit or whatever tool you prefer).
After that, reinstall Python, and it should install pip as intended.
I am using python 3.6.2 and faced a similar issue of missing scripts folder(also pip script) in python folder. I have done following things to add scripts folder again to python.
Goto - Control Panel\All Control Panel Items\Programs and Features
then look for python program and try to uninstall it. A pop window
will appear which shows the following image.
Image Python
Try to REPAIR the installed program that should fix the issue.
Otherwise click on MODIFY and tick on pip check box and Add Python to environment variables checkbox, then install it. This should fix the issue.
Even I was facing this issue. I solved it by doing the following steps:
Uninstall python. (you can use the installer(python-2.7.xx.msi) to perform the uninstall. Select the option 'Remove Python'on double clicking the installer.)
Edit the environment variable 'Path', and remove the python directory path. ( To change the environment variable, right click on 'This PC', click properties, click 'Advanced System Properties' ->Environment Variables)
Remove the environment variable 'Python Path' if present.
Now reinstall python.
It will work !!!
Actually Scipts folder will not create after installing python, you have to manually create this folder and then install pip, then you can find the required files in this directory.
I had also faced the same problem which i managed to solve. The problem is when you install the python in default configuration then it installs the python folder in the "c:\user\Appdata......" which is lengthy and hard to find . To avoid it first uninstall the python 3.7 completely from the system from the control panel ->uninstall program. Then install it again with the option " customize installation". On the next page change the default location to C:/Python/Python37-32 and select the required check boxes and click install. This should solve your problem.
It is permission issue. I have both python 2 and 3 installed under
C:\Program Files\python\2.7.16
C:\Program Files\python\3.7.2
Python 2 installer is msi, so there is no run as admin option when install it
Python 3 installer is exe, there is run as admin option.
As the results, python 2 installed without scripts and pip.exe and python 3 installed successfully.
To fix this, simply give the full permission to everyone on
C:\Program Files\python\ and install python 2 again. then change the permission back.
That's it.
This Command works fine for me:
python -m ensurepip
Looking in links: C:\Users\kjangala\AppData\Local\Temp\tmpvd4_442i
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-19.0.3 setuptools-40.8.0
I had this issue after getting a new computer and restoring my appdata folder (an enterprise system did this automatically for me). Somehow some old metadata in my %userprofile%\AppData\Local\Programs\Python folder made the Scripts folder inside end up empty when I reinstalled Python.
I deleted this folder and uninstalled/reinstalled Python, and everything is working again.
Edit: I also had to delete %userprofile%\AppData\Roaming\Python to resolve another similar error. Interestingly, this one didn't get recreated on the reinstall.
It is simple,
Download this file Get Pip. Save it in your local with the extension .py
To run in windows:
1.) Open cmd
2.) type "python" and check if python is been installed
3.) type "python filePath.py" (example if you saved your file in C drive go the particular folder and run the command - Here "filePath.py" is the filename you saved)
command looks like this
4.) Cheers now it should work
5.) To check if pip installed properly type "pip --version"
I had the same issue (win 10, py 3.8.5, executable installer). The solution i've found is to install python to non-standard catalog (D:/ instead of windows user folder which is under access protection). In this case, the file "easy_install.exe" will be created in the Scripts folder. Then open console inside the folder and call "easy_install pip", this will install pip. After that just copy everything to the standard catalog and don't forget to change the environment variables.

Categories

Resources