I am a beginner to Python and am having great difficulty in running my python googleppengine code locally on my machine.
My code looks as follows:
import json
import urllib
import os
import webapp2
from google.appengine.ext.webapp import template
import datetime
from google.appengine.ext import db
class Events(db.Model):
venue_name = db.StringProperty()
address = db.StringProperty()
id = db.StringProperty()
venue_id = db.StringProperty()
# hire_date = db.DateProperty()
# attended_hr_training = db.BooleanProperty()
class eventSearch(webapp2.RequestHandler):
def get(self):
base_url = 'http://api.eventful.com/json/events/search?app_key=zGtDX6cwQjCRdkf6&l=dublin&?q=music'
response = urllib.urlopen(base_url)
html = response.read()
html = json.loads(html)
result = html['venues']
result1 = result['venue']
When I run this code in my cmd prompt with command "python file.py", I receive the following error:
Traceback <most recent call last>:
File "file.py", line 4, in <module>
import webapp2
ImportError: No module named 'webapp2'
I have 1. Created a PythonPath as suggested in How to add to the pythonpath in Windows? within my system variables with directories:
C:\Python33\DLLs;C:\Python33\Lib;C:\Python33\Lib\lib2to3;C:\Program Files (x86)\Google\google_appengine;C:\Program Files (x86)\Google\google_appengine\lib;
I have then also added both of the below directories into my "PATH" variable also, as recommended within answer - import webapp2 works on google-app-engine even though I don't have webapp2 installed
C:\Program Files (x86)\Google\google_appengine\;C:\Program Files (x86)\Google\google_appengine\lib
EDIT:
After suggestions within the answers provided I too have realized that GAE does not support version 3.3 of Python I was trying to run it with in my previous part of my question.
After uninstalling Python33 and installing Python27 instead, changing my system variables to reflect the new Python27, I am still having issues and my code will not upload with the GAE launcher.
I receive the following errors within my log-console (GAE Launcher):
2013-04-14 22:59:19 Running command: "['C:\\Python27\\pythonw.exe', 'C:\\Program Files (x86)\\Google\\google_appengine\\dev_appserver.py', '--skip_sdk_update_check=yes', '--port=8080', '--admin_port=8001', 'C:\\Users\\Karen\\Desktop\\Development\\projects\\file']"
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\dev_appserver.py", line 193, in <module>
_run_file(__file__, globals())
File "C:\Program Files (x86)\Google\google_appengine\dev_appserver.py", line 189, in _run_file
execfile(script_path, globals_)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 30, in <module>
from google.appengine.datastore import datastore_stub_util
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\datastore\datastore_stub_util.py", line 45, in <module>
from google.appengine.api import api_base_pb
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\api_base_pb.py", line 20, in <module>
from google.net.proto import ProtocolBuffer
File "C:\Program Files (x86)\Google\google_appengine\google\net\proto\ProtocolBuffer.py", line 22, in <module>
import httplib
File "C:\Python27\lib\httplib.py", line 71, in <module>
import socket
File "C:\Python27\lib\socket.py", line 47, in <module>
import _socket
ImportError: Module use of python25.dll conflicts with this version of Python.
2013-04-14 22:59:21 (Process exited with code 1)
Thank you for any help that you can provide me.
You should not install webapp2. It is included in the SDK, and is already in the production runtime.
Have a read of Configuring libraries that are part of the appengine environment https://developers.google.com/appengine/docs/python/python25/migrate27#Configuring_Libraries
and here is the list of included 3rd party libs.
https://developers.google.com/appengine/docs/python/tools/libraries27
If you use pip/easy_install for various other libs, you will find on its own that is insufficient. You will need to link or include these libs in your project, manipulate sys.path so they can be found, and make sure these libraries are deployed.
This solved my problem (same problem you got)
First don't try to run from python IDLE run from Google app engine open localhost:port
Open log in GAE if still showing same error try below steps
Check your python version 2.7.X or 3.X
If 3.x install 2.7.8
Then open google app engine console and go to edit > preferences
add your python27 directory (ex:C:\Python27\pythonw.exe) to PythonPath click ok
It looks like appengine/tools/devappserver2/python/sandbox.py is supposed to turn C:\path\to\google_appengine\google into C:\path\to\google_appengine, but there is an extra dirname, so it ends up getting C:\path\to. I'm not sure why it only causes problems in some circumstances.
You can work around the problem by changing:
library_pattern = os.path.join(os.path.dirname(
os.path.dirname(google.__file__)), _THIRD_PARTY_LIBRARY_FORMAT_STRING)
to:
library_pattern = os.path.join(
os.path.dirname(google.__file__), _THIRD_PARTY_LIBRARY_FORMAT_STRING)
I found this issue by putting raise Exception(sys.path) in various places in the app engine code and restarting the dev server.
You can install webapp2 by using pip or easy_install. Refer to http://webapp-improved.appspot.com/tutorials/quickstart.nogae.html for quick stark
Related
I had some system updates for my manjaro installation and after that I get the following error message when trying to run gcloud:
gcloud components update
Traceback (most recent call last):
File "/home/mani/Downloads/google-cloud-sdk/lib/gcloud.py", line 104, in <module>
main()
File "/home/mani/Downloads/google-cloud-sdk/lib/gcloud.py", line 62, in main
from googlecloudsdk.core.util import encoding
File "/home/mani/Downloads/google-cloud-sdk/lib/googlecloudsdk/__init__.py", line 23, in <module>
from googlecloudsdk.core.util import importing
File "/home/mani/Downloads/google-cloud-sdk/lib/googlecloudsdk/core/util/importing.py", line 23, in <module>
import imp
File "/usr/lib/python3.9/imp.py", line 23, in <module>
from importlib import util
File "/usr/lib/python3.9/importlib/util.py", line 2, in <module>
from . import abc
File "/usr/lib/python3.9/importlib/abc.py", line 17, in <module>
from typing import Protocol, runtime_checkable
File "/usr/lib/python3.9/typing.py", line 26, in <module>
import re as stdlib_re # Avoid confusion with the re we export.
File "/usr/lib/python3.9/re.py", line 124, in <module>
import enum
File "/home/mani/Downloads/google-cloud-sdk/lib/third_party/enum/__init__.py", line 26, in <module>
spec = importlib.util.find_spec('enum')
AttributeError: module 'importlib' has no attribute 'util'
After looking online I found that the problem could be that this version of gcloud doesn't support python3.9 and the recommended solution was to run gcloud components update but that gives the same error. Is there a way I could revert or make the command use an older python version to upgrade itself then go back to the new python 3.9?
As per following GCP official document you can restore your Cloud Shell VM to it's original state by removing the home directory as follows:
ls -a $HOME
sudo rm -rf $HOME
Now in the Cloud Shell click on the three dot menu and restart the VM will create an new VM and home directory will be restore as it's default state.
As you have the issue in your local machine, after researching I have noticed following PIT1 as a bug in Google Issue Tracker. There are few WA for now on the following thread you can apply it accordingly.
There is another PIT2 as a Feature request to add support for python 3.9. Feel free to post there should you have any additional comments or concerns regarding the issue.
Another WA found in the github might be useful for your use case.
Note: Please don't comment here that Python 2.7 is depreciated. I already know this. I need to get this working first before migrating to 3.x.
On Windows 10, I had installed (and running correctly) both Python 2.7 and Python 3.7. Since I only needed Python 2.7, I uninstalled Python 3.7 (and manually deleted respective packages installed under .\Python37*) as well as the virtual environment directory below. I have no idea if that virtual environment was associated with Python 2.7 or Python 3.7:
C:\Users\MKANET\Envs\MKA.NETT
After I rebooted, to my horror, every time I run a Python 2.7 script, I get a whole bunch of ambiguous traceback errors when trying to import modules I had installed with PIP (for Python 2.7). However, I don't have issues importing the modules like sys, json (packages that come preinstalled with Python 2.7).
When executing script below from Windows command-line:
& C:/Users/MKANET/AppData/Local/Programs/Python/python27/python.exe c:/Users/MKANET/OneDrive/Dev/Projects/Python/test2.py
...I get a bunch of ambiguous traceback errors:.
Traceback (most recent call last):
File "c:/Users/MKANET/OneDrive/Dev/Projects/Python/test2.py", line 3, in <module>
from pypsexec.client import Client
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\pypsexec\client.py", line 8, in <module>
from smbprotocol.connection import Connection, NtStatus
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\smbprotocol\connection.py", line 33, in <module>
from cryptography.hazmat.primitives.ciphers import (
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\cryptography\hazmat\primitives\ciphers\aead.py", line 10, in <module>
from cryptography.hazmat.backends.openssl import aead
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\cryptography\hazmat\backends\openssl\__init__.py", line 7, in <module>
from cryptography.hazmat.backends.openssl.backend import backend
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\cryptography\hazmat\backends\openssl\backend.py", line 16, in <module>
from cryptography import utils, x509
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\cryptography\x509\__init__.py", line 8, in <module>
from cryptography.x509.base import (
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\cryptography\x509\base.py", line 18, in <module>
from cryptography.x509.extensions import Extension, ExtensionType
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\cryptography\x509\extensions.py", line 26, in <module>
from cryptography.x509.general_name import GeneralName, IPAddress, OtherName
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\cryptography\x509\general_name.py", line 10, in <module>
from email.utils import parseaddr
File "c:\Users\MKANET\OneDrive\Dev\Projects\Python\email.py", line 11, in <module>
obj = win32com.client.Dispatch("Outlook.Application")
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\win32com\client\dynamic.py", line 114, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)
UPDATE HUGE CLUE:
This is ONLY happens when executing scripts in the below folder:
C:\Users\Michael\OneDrive\Dev\Projects\Python
If I execute a script in any other folder on my C: Drive, modules load perfectly without errors. I don't know what's different about this folder that causes my modules not load. Maybe, there's a file in this folder that causing this?
Since this issue was limited only to scripts inside the below directory:
C:\Users\Michael\OneDrive\Dev\Projects\Python
I was able to narrow the issue down to a file called, email.py. If I tried to import a module for example, requests; for some odd reason an email.pyc would get created; followed by the import module errors. All I did was rename email.py to mail.py.. and, this whole issue finally stopped.
I have no idea why Python 2.7 is sensitive to that file name, but changing it to something else resolved the issue for me. Maybe, someone could comment on why the file name breaks things; especially when I had a __init__.py in the same directory to import another module.
Traceback (most recent call last):
File "manage.py", line 6, in <module>
from app import create_app, db
File "C:\Users\miran\Dropbox\PyReddit-master\app\__init__.py", line 6, in <module>
from instance.config import app_config
ModuleNotFoundError: No module named 'instance'
I am testing out this repository (https://github.com/tuvtran/PyReddit) and it keeps telling me there is no module instance, I have searched but found nothing that helped the error. The venv is in the same folder as the script.
Essentially this is occurring because the app\__init__.py is is importing a file in the instance directory. As per the Flask documentation, this directory normally contains instance configuration overrides default configurations.
Unfortunately, the project currently saves its default configurations in this directory, but it is not checked into Git (see .gitignore). To fix this:
Remove from instance.config import app_config
Add a configuration file following these instructions
Import the configuration file you just created
Replace app.config.from_object(app_config[config_name]) with app.config.from_object(your_configuration)
I wanted to use pyueye module to manipulate my IDS camera. I've installed latest drivers from manufacturer's website and I can manage the camera by using uEye Cockpit appliaction. I wanted to write some python script to use with camera, but i can't even import pyueye module.
My code:
import ctypes
from pyueye import ueye
print(ueye.__version__)
Error info:
C:\Python\python.exe C:/Users/Karol/PycharmProjects/ids_camera/ids_test.py
Traceback (most recent call last):
File "C:\Python\lib\site-packages\pyueye\dll.py", line 165, in load_dll
dll = DLL(libinfo, libnames, os.getenv(envname))
File "C:\Python\lib\site-packages\pyueye\dll.py", line 96, in __init__
raise RuntimeError("could not find any library for {} ({})".format(libinfo,
dllmsg))
RuntimeError: could not find any library for ueye_api (DLL_PATH: unset)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
\File "C:/Users/Karol/PycharmProjects/ids_camera/ids_test.py", line 2, in
<module>
from pyueye import ueye
File "C:\Python\lib\site-packages\pyueye\__init__.py", line 55, in <module>
from . import ueye
File "C:\Python\lib\site-packages\pyueye\ueye.py", line 54, in <module>
get_dll_file, _bind = load_dll("ueye_api", ["ueye_api_64", "ueye_api"],
"PYUEYE_DLL_PATH")
File "C:\Python\lib\site-packages\pyueye\dll.py", line 167, in load_dll
raise ImportError(exc)
ImportError: could not find any library for ueye_api (DLL_PATH: unset)
Process finished with exit code 1
I have installed that module via pip, my OS is Win 7 x64, my python interpreter is 3.6, also *.dll files associated with ueye are installed in C:\Windows... folder. I also copied ueye_api.dll and ueye_tools.dll files to pyueye directory, but it didn't help.
I tried adding ueye_api_64.dll from C:\Program Files\IDS\uEye\USB driver package to my pyueye folder. I also added this location to the system variable's PATH and this solved the problem for me.
Try the following things:
Restart your computer after the installation.
Make sure the DLL is in your C:\Windows\System32 directory.
Set PYUEYE_DLL_PATH to the directory of where the DLL is located.
When nothing of that helps please contact the IDS support.
I only put the DLL in the C:\Windows\System32 directory and it works right away. No restart, no addition to PATH.
Cheers.
(Python3)
I wrote a program it works fine without any errors when I run it from the python interpreter, I then used py2exe to turn it in to an .exe but when I run it it does'nt work anymore... I get this error:
Traceback (most recent call last):
File "pass.py", line 1, in <module>
File "dropbox\__init__.pyc", line 3, in <module>
File "dropbox\client.pyc", line 22, in <module>
File "dropbox\rest.pyc", line 26, in <module>
File "pkg_resources.pyc", line 950, in resource_filename
File "pkg_resources.pyc", line 1638, in get_resource_filename
NotImplementedError: resource_filename() only supported for .egg, not .zip
Am I supposed to do something when using py2exe when I have downloaded modules imported into the program?
these are the modules imported :
import dropbox
import os
import getpass
from time import sleep
please help !
I fixed this problem using the solution found here
basically you modify ~line 26 in rest.py found in the dropbox library
to this:
try:
TRUSTED_CERT_FILE = pkg_resources.resource_filename(__name__, 'trusted-certs.crt')
except:
# if current module is frozen, use library.zip path for trusted-certs.crt path
# trusted-certs.crt must exist in same directory as library.zip
if hasattr(sys,'frozen'):
resource_name = sys.prefix
resource_name.strip('/')
resource_name += '/trusted-certs.crt'
TRUSTED_CERT_FILE = resource_name
else:
raise
and then place the trusted-certs.crt file also found in the dropbox library in the same folder as your executable