pyinstaller single exe of program which uses google api client lib - python-2.7

I have a python program which I've successfully packaged up as a single exe using pyinstaller in the past. Recently I added new features which make use of the google api python client ( https://developers.google.com/api-client-library/python/ ). I've attempted to make a new single exe package of the new version and it fails to run.
I enable debugging and the console and initially the issue was that it hadn't picked up the oauth lib. I fixed that by adding the following to my spec file:
hiddenimports=['googleapiclient', 'apiclient']
When I build I can see this:
53092 INFO: Hidden import 'googleapiclient' has been found otherwise
53093 INFO: Hidden import 'apiclient' has been found otherwise
However, now when I run the rebuilt exe I get the following error before it exits:
pkg_resources.DistributionNotFound: google-api-python-client
I can't see any reference to that and I'm not sure how to force it to be packaged up with the exe.
I figure I can't be the only person to have ever wanted to package up a python program that makes use of the google api, but I failed to find any help during a lot of time with my friend google...
Any tips?

Many People Have same question but I can't find any answer
Try This way
find site package of your project
enter the Pyinstaller/hooks and find hokk-google.api_core.py
add line ( edit line ) datas += copy_metadata('google-api-python-client')
example
from PyInstaller.utils.hooks import copy_metadata
datas = copy_metadata('google-api-core')
datas += copy_metadata('google-api-python-client')
excute pyinstaller hidden-import google-api-python-client
pyinstaller --hidden-import google-api-python-client
you can avoid error
pkg_resources.DistributionNotFound: google-api-python-client

I was able to dig deeper into this issue after I switched from using pip to easy_install to install the google-api-python-client package. Manually installing the egg file gave me a much neater way of testing.
I then started building using pyinstaller with out the --onefile option, this way I was able to start messing with the egg file that was packaged up with my program. Eventually I found out that my problem was stemming from the fact I'm making use of Pandas and the Google API.
Here's the relevant Pandas bug on github.
To solve the problem I had to update my version of Pandas.
I did find that if I moved to the most recent version of Pandas (1.6.0) I ran into a new issue because it imports dateutil and it causes problems looking for the zoneinfo file. I've landed on Pandas 1.5.1 and it is all working.

You can also add site-packages using:
--add-data "path_to_your_package:package_name(e.g googleapiclient)"

Related

AWS Lambda using PIL/Pillow with Python 2.7

I'm using Python 2.7 (for various reasons) on AWS Lambda, and I need to use the PIL/Pillow library for image processing. I'm using a ZIP file to get code into my Lambda function.
One of the items in this zip is a folder with the PIL library in it. I've tried several different methods of getting the library in there, including using pip install pillow -t ., and using pre-compiled PIL libraries from here and here.
Using the first pre-compiled source, I get the error:
no module named PIL
If I rename the subdirectory from PIL to pillow, I get the same error but with pillow.
Using the second pre-compiled source and the pip method, I get the error:
Could not import the Python Imaging Library (PIL) required to load image files
Here's my import statement and the line that the error is occurring on:
from pillow import *
...
I = imread(filename, flatten=True)
Here's a screenshot of my file structure (using the 1st pre-compiled source):
Archive.zip is what I've been uploading to Lambda. Each time I make a code or library change, I recreate this by selecting each of the files I would like to zip, right-clicking and selecting "Compress". I'm using macOS High Sierra.
Btw, I've seen this question and answer, but I'm not getting the same error message and I couldn't get the suggested commands to work anyway.
I'm wondering if it could be an issue with PIL vs Pillow or with Python 3.6 vs Python 2.7.
Any help is much appreciated!
I solved this by using a Docker solution, as outlined in this post.

When I try to compile and .exe I get ImportError: No module named six

I've tried making an exe from a program using py2exe, cx_freeze and pyinstaller. All of which give me an error 'ImportError: No module named six' when I go to launch the .exe
The .exe is able to be created. I've looked through the forums and all of them say to pip install six (it's already installed). I've tried uninstalling and re-installing six.
One post mentioned uninstalling matplotlib, so I did that.
When I instlalled pyinstaller one of the requirements was that six be installed! So this is very baffling.
http://i289.photobucket.com/albums/ll233/89733/stacked_help_zpsnrvlayj4.jpg
After Gabriel asked for the screenshot I took a closer look.
pip install urllib3 --upgrade solved the issue, which I found here:
https://github.com/transifex/transifex-client/issues/103
When you create a .exe file using cx_freeze it kind of compiles all the needed libraries into the .exe folder, you probably had to configurate a setup file from cx_freeze to be able to create the .exe, right? There you must "tell" cx_freeze which libraries are going to be needed when someone runs the program.
Keep in mind that when you create a .exe you dont need to have python neither six to run it.

Global name 'col2im_6d_cython' is not defined, CS231n

I'm following CS231n and met a problem when doing assignment2: ConvolutionalNetworks: global name 'col2im_6d_cython' is not defined.
I think the problem was due to a failure in importing functions from im2col_cython.pyx, which used cython.
I've installed Xcode 7.3.1, as shown below, but the problem was still not solved.
I'm running the ipynb files in Jupyter from Anaconda. There is a related discussion on reddit, but unfortunately the solution here was for Windows, not Mac OS X.
Thank you for your time.
I wanted to add my input as a comment but didn't have enough reputation points to do so.
The issue was resolved for me when I closed the jupyter notebook and opened it again. I compiled the cython extension after I got the import error and probably have to relaunch it when the .so file is available.
I solved this with 2 easy steps:
In the terminal, run python setup.py build_ext --inplace in the cs231n directory.
Then reopen the notebook (if necessary, shutdown the notebook, the open it again);
Ps.: I tried this through the notebook using !python ./cs231n/setup.py build_ext --inplace as well. It does not work! You have to that outside the notebook, using the terminal.
I had this problem recently. I googled it a lot and also tried un-/-reinstall Anaconda. However it does work further. So I used "which python" to figure out which python's been using. And it turns out that the python included in Anakonda directory is used as default. I then tried the python2.7 in my macOS, which is located in /usr/bin/python2.7. Although I got a couple of warnings, but now it works likes charm. Perhaps it's kind of version problem. Solved in macOS Sierra 10.12.4.
I compared the two compiling results, as it shows that the include files are totally different. The one in Anaconda includes all header files in python3.6. Instead we need here corresponding header files in python2.7(I suppose). As the red circles point out.
enter image description here
Supported by python 3 onwards. Go to setup_googlecloud.sh and change the line
virtualenv .env
to
virtualenv -p python3 .env and run the setup again as explained in assignment1 setup..
Works well after that..
It occurred to me as well.
My problem:
I saw that the extention file that is created is named "im2col_cython.cp37-win_amd64.pyd" and the import is looking for im2col_cython alone, so I changed the file name to "im2col_cython.pyd" and ran the setup script again.
Now when I ran the code in the notebook it found the module but it said that the dll was compiled with a different python version. I use Anaconda envs and it turns out that since I ran the setup script from the cmd, it used a different python version than the one of the environment. I deleted the created files from the cs231n directory (im2col_cython.cp37-win_amd64.pyd and im2col_cython.c) and ran the setup script again, this time from the env Anaconda Prompt and it worked.
Solution:
remove already created files (the .c and .pyd files)
run the setup
script from the environment prompt (not plain cmd)
change the .pyd
file name into im2col_cython.pyd
Enjoy!

How to install GDAL/scipy using cmd in window?

I downloaded scipy-0.17.0-cp27-none-win_amd64.whl and GDAL-1.11.4-cp27-none-win_amd64.whl from gohlke in C:\Python27\Scripts
To install I used
pip install scipy-0.17.0-cp27-none-win_amd64.whl
pip install GDAL-1.11.4-cp27-none-win_amd64.whl
It says the installation is complete but when I import the libraries as
import scipy
import gdal
it shows error as
No module named gdal
No module named gdal
However, I installed the matplotlib, numpy in the very same way and they are working absolutely fine.
I solved this problem eventually to found the mistake in my approach.
This problem can occur with anyone using ArcGIS in one's system.
ArcGIS comes with it's default Python package and if one installs python separately, each time the new libraries gets installed in the newer Python installation not in ArcGIS.
Therefore, the pyhton IDLE which one uses need to be from another Python installation.
Here in my case, ArcGIS has Python 2.6 and I have made an separate installation using Python 2.7.11.
All the libraries were getting installed in right place but I was opening the wrong IDLE to write scripts hence getting error.

Aptana Python stdlib issue with virtualenv

I recently started working on a project using just vim as my text editor with a virtualenv setup. I installed a few API's on this virtualenv from GitHub. Eventually, the project got a little bigger than vim could handle so I had to move the project to an IDE.
I chose Aptana Studio 3. When I started up Aptana, I pointed the project directory to the virtualenv folder that I had created to house my project. I then pointed the interpreter at the Python executable in App/bin (created from virtualenv)/python2.7. When I started reworking the code to make sure I had everything mapped correctly, I was able to import the API's that I had installed just fine. CherryPy came through with no problems, but I've been having an issue with importing a module that I believe is part of the stdlib--urlparse. At first, I thought it was that my python interpreter was 2.7.1 rather than 2.7.5 (I found the documentation in the 2.7.5 section with no option to review 2.7.1), but my terminal is using 2.7.1 and is able to import the module without any errors (I'm using OSX, Mountain Lion). I am also able to import the module when I activate the virtualenv and run my python interpreter. But when I plug "from urlparse import parse_qsl" into Aptana, I'm getting an error: "Unresolved_import: parse_qsl".
Should I have pointed this at a different interpreter and, if so, will I need to reinstall the API modules I had been working with in the new interpreter?
Update: I finally ended up restarting the project. It turns out that not all of the standard Python tools are selected when you select the virtualenv interpreter. After I selected all of the python tools from the list (just after choosing the interpreter), I was able to get access to the entire standard library.
Do NOT just import the modules into your project. Many of the stdlib modules are interdependent and the import function will only import a module into your main project directory, not a libary!