I build a google translate application and it was running fine in pycharm. When I converted the files into single executable file using pyinstaller the executable file is not running. I have imported from google.cloud import translate_v2
Error message is noted below:
pkg_resources.DistributionNotFound: The 'google-cloud-translate' distribution was not found and is required by the application
Please help where went wrong.Let me know if any other details required
Add this parameter to the command line when running pyinstaller:
--copy-metadata google-cloud-translate
But actually, if you use a newer PyInstaller version, the automatic bytecode scanning should do that for you.
Thanks. I have solved the issue by editing the code in the below path
C:\Users\3888123\AppData\Local\Programs\Python\Python39\Lib\site-packages\google\cloud\translate_v2_init_.py
From
from pkg_resources import get_distribution
__version__ = get_distribution("google-cloud-translate").version
from google.cloud.translate_v2.client import Client
__all__ = ("__version__", "Client")
To
__version__ = "4"
from google.cloud.translate_v2.client import Client
__all__ = ("__version__", "Client")
Result
Single executable file created with out error. Hope this answer helps some one.
Related
I am using python 2.7.11 on Windows 7 64bit, I am facing a problem with py2exe when I import paramiko module, the .exe file runs but does not show any results, after executing it closes immediately knowing that i did not get any error during the conversion.
import paramiko
print raw_input("press enter to exit")
the setup.txt file:
from distutils.core import setup
import py2exe
setup(console=['test.py'])
I have found that in the "dist" folder there are some dll files such as API-MS-Win-Core-ErrorHandling-L1-1-0.dll - API-MS-Win-Core-LibraryLoader-L1-1-0.dll - API-MS-Win-Core-LocalRegistry-L1-1-0.dll, such files I don't usually face them on another machine, so could anyone help please.
I was able to solve this after importing some modules:
import appdirs
import packaging
import packaging.version
import packaging.specifiers
import packaging.requirements
hopefully that could be useful for someone.
My python script includes a Qt GUI which I'm trying to convert into a Windows executable using Py2exe. My script is using the Tweepy module to fetch data from Twitter. So I include Tweepy and try to compile it into an executable using the following Setup.py:
from distutils.core import setup
import py2exe
setup(
windows = [{"script": "main.py"}],
options = {"py2exe":{"includes":["sip", "tweepy"]}}
)
The following Error gets raised:
raise ImportError, "No module named " + qname
ImportError: No module named tweepy
I've succesfully used the same setup file (minus the 'Tweepy include') to compile other script in the past. What am I missing here?
Assuming that you have tweepy installed in the python installation that you are trying to build with try adding:
import tweepy
near the start of your setup.py to ensure that py2exe can really see it, some packages do some interesting things during import.
Im trying to compile Godot engine following the instructions here
When I run scons bin/godot as the tutorial says, I get the following error:
scons: Reading SConscript files ...
ImportError: cannot import name _args_from_interpreter_flags:
File "/home/grayfox/github/godot2/godot/SConstruct", line 9:
import multiprocessing
File "/usr/lib64/python2.7/multiprocessing/__init__.py", line 65:
from multiprocessing.util import SUBDEBUG, SUBWARNING
File "/usr/lib64/python2.7/multiprocessing/util.py", line 40:
from subprocess import _args_from_interpreter_flags
The SConstruct file starts this way:
EnsureSConsVersion(0,14);
import string
import os
import os.path
import glob
import sys
import methods
import multiprocessing
...
If I try to run python SConstruct I get an error complaining about missing functions defined by scons (i.e. the script fails after doing all the imports).
Commenting import multiprocessing fixes the issue but I don't want to modify that file, as I would have to revert the change if I ever make a pull request. The project is quite active so I believe this has something to do with my local configuration.
Any ideas why the script is failing to import _args_from_interpreter_flags only if I execute it via scons?
[UPDATE]
I did a fresh Gentoo install and the problem persists. I did some tests and I found this:
In a python terminal>
>>> import SCons.Script
>>> from subprocess import _args_from_interpreter_flags
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name _args_from_interpreter_flags
>>> import subprocess
>>> subprocess.__file__
'/usr/lib64/python2.7/site-packages/SCons/compat/_scons_subprocess.pyc'
But the output is different if I do this:
>>> import subprocess
>>> subprocess.__file__
'/usr/lib64/python2.7/subprocess.pyc'
So I update my question: Is this a bug? Can anybody reproduce it in other distros? If it's a bug, should I report it to Gentoo or to SCons?
[ANOTHER UPDATE]
Adding temp.extend([os.path.join(x, 'lib64') for x in prefs]) did't work, same error.
Adding print sys.path at the beginning of the compact module gives:
['/usr/lib64/python-exec/python2.7/scons-local-2.3.0',
'/usr/lib64/python-exec/python2.7/scons-local',
'/usr/lib64/python2.7/site-packages/lib32/scons-2.3.0',
'/usr/lib32/scons-2.3.0',
'/usr/local/lib32/scons-2.3.0',
'/usr/lib64/python2.7/site-packages/lib/python2.7/site-packages/scons-2.3.0',
'/usr/lib/python2.7/site-packages/scons-2.3.0',
'/usr/local/lib/python2.7/site-packages/scons-2.3.0',
'/usr/lib64/scons-2.3.0',
'/usr/lib64/python2.7/site-packages/lib32/scons',
'/usr/lib32/scons',
'/usr/local/lib32/scons',
'/usr/lib64/python2.7/site-packages/lib/python2.7/site-packages/scons',
'/usr/lib/python2.7/site-packages/scons',
'/usr/local/lib/python2.7/site-packages/scons',
'/usr/lib64/scons',
'/usr/lib64/python2.7/site-packages/RBTools-0.6-py2.7.egg',
'/usr/lib64/python27.zip',
'/usr/lib64/python2.7', #It's here, so what's the problem?
'/usr/lib64/python2.7/plat-linux2',
'/usr/lib64/python2.7/lib-tk',
'/usr/lib64/python2.7/lib-old',
'/usr/lib64/python2.7/lib-dynload',
'/usr/lib64/python2.7/site-packages',
'/usr/lib64/python2.7/site-packages/gtk-2.0',
'/usr/lib64/python2.7/site-packages/wx-2.8-gtk2-unicode']
It looks as if this isn't really a problem connected to SCons directly. You might have an alien "subprocess" module/package installed in your system. Also check out Cannot import name _args_from_interpreter_flags which seems to be related.
Based on your updated question: I tried to compile Godot on my machine (Python 2.7.3, SCons 2.3.1, Ubuntu 12.04 LTS) and it's running fine, so the problem is not related to the provided SConstruct (and its supporting build description files in subfolders). The "_scons_subprocess" module gets used only when the import of the original "subprocess.py" fails. So I suspect that the SCons start script sets up a wrong sys.path, which may happen under 64bit (see issue http://scons.tigris.org/issues/show_bug.cgi?id=2657 ).
After you added "temp.extend([os.path.join(x, 'lib64') for x in prefs])", your "print sys.path" statement shows paths like "/usr/lib64/python-exec" in its output. A Google search turned up the page http://forums.gentoo.org/viewtopic-t-985402-start-0.html for me. It describes an issue with Gentoo, where programs are installed as links to pip. Please follow the given advice and see if this fixes your problem.
It's a bug in Gentoo's scons-2.3.0 and scons-2.3.1 ebuilds (see bug report). It has been fixed in versions 2.3.1-r1 and higher.
after runing this code,I found import error:-
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
class MainPage(webapp.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Hello, webapp World!')
application = webapp.WSGIApplication([('/', MainPage)],debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
how to use google.apengine.ext
import sys
sys.path.insert(1, '/Users/<username>/google-cloud-sdk/platform/google_appengine')
sys.path.insert(1, '/Users/<username>/google-cloud-sdk/platform/google_appengine/lib/yaml/lib')
sys.path.insert(1, 'lib')
if 'google' in sys.modules:
del sys.modules['google']
this solves the problems for me
It looks like the App Engine SDK is not installed, or at least the Python runtime cannot find it.
read and follow the instructions here: https://cloud.google.com/appengine/downloads#Google_App_Engine_SDK_for_Python
They tell you, how to install App Engine SDK for Python.
Try:
import google
print google.__path__
to see what exactly you're importing.
I had this same issue because I pip installed gcloud before downloading and installing the SDK. The pip install created a python package google which didn't contain the appengine submodule (which is found in the SDK folder). I uninstalled the gcloud and related packages. Then just pip installed the google-cloud-bigquery which is the only package I needed from gcloud. Everything works fine now.
I faced similar error while calling Google Analytics API using AWS Lambda.
Workaround from (Schweigi1) helped me.
import googleapiclient
from googleapiclient.discovery_cache.base import Cache
class MemoryCache(Cache):
_CACHE = {}
def get(self, url):
return MemoryCache._CACHE.get(url)
def set(self, url, content):
MemoryCache._CACHE[url] = content
Usage:
service = googleapiclient.discovery.build("analyticsreporting", "v4", http=http, credentials=credentials,cache=MemoryCache())
Hope this helps someone who is facing this issue in AWS Lambda.
First possible reason:
you don't install the python library in google cloud sdk, so you can run in cmd (as administrator):
gcloud components install app-engine-python.
Second possible reason:
your IDE is not success get into google libraries, they exist in:
C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine
or in:
C:\Users\[your user]\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine
You can see in attached link explain how to add these libraries to IDE external libraries: https://stackoverflow.com/a/24206781/8244338
I got this error in python:
from google.appengine.api import search
ImportError: No module named appengine.api
I thought this would be something along the similar lines of what is happening in this thread.
So, my solution was to run "dev_appserver.py 'your yaml file' ". I got this solution following the below links:
1) https://cloud.google.com/appengine/docs/standard/python/tools/using-local-server
2) https://www.youtube.com/watch?v=BdqUY8lCuBI
Hope this helps!
check if you named some file google.py :) in the same package, because this can shadow the import of google.appengine.ext. I had the same error:
python import error “No module named appengine.ext”
and deleteting the file solved the problem.
I have a problem with making exe using py2exe. In my project i'm using sqlalchemy with mssql module.
My setup.py script looks like:
from distutils.core import setup
import py2exe
setup(
windows=[{"script" : "pyrmsutil.py"}],
options={"pyrmsutil" : {
"includes": ["sqlalchemy.dialects.mssql", "sqlalchemy"],
"packages": ["sqlalchemy.databases.mssql", "sqlalchemy.cresultproxy"]
}})
But when i'm starting procedure like:
python.exe setup.py py2exe
I'm receiving build log with following errors:
The following modules appear to be missing
['_scproxy', 'pkg_resources', 'sqlalchemy.cprocessors', 'sqlalchemy.cresultproxy']
And in "dist" folder i see my pyrmsutil.exe file, but when i'm running it nothing happens. I mean that executable file starts, but do nothing and ends immediately without any pyrmsutil.exe.log. It's very strange.
Can anybody help me with this error?
I know it's no an answer per se but have you tries pyInstaller? I used to use py2exe and found it tricky to get something truly distributable. pyInstaller requires a little more setup but the docs are good and the result seems better.
For solving this issue you could try searching for the mentioned dlls and placing them in the folder with the exe, or where you build it.
Looks like py2exe can't find sqlalchemy c extensions.
Why not just include the egg in the distribution, put sqlachemy in py2exe's excludes and load the egg on start?
I use this in the start script:
import sys
import path
import pkg_resources
APP_HOME = path.path(sys.executable).parent
SUPPORT = APP_HOME / 'support'
eggs = [egg for egg in SUPPORT.files('*.egg')]
reqs, errs = pkg_resources.working_set.find_plugins(
pkg_resources.Environment(eggs)
)
map(pkg_resources.working_set.add, reqs)
sys.path.extend(SUPPORT.files('*.egg'))
i use Jason Orendorff's path module (http://pypi.python.org/pypi/path.py) but you can easily wipe it out if you want.