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)
Related
I'm getting the following error trying to run Django using apache:
mod_wsgi (pid=3294): Target WSGI script '/www/cocurate2_dev/startup.wsgi' cannot be loaded as Python module.
mod_wsgi (pid=3294): Exception occurred processing WSGI script '/www/cocurate2_dev/startup.wsgi'.
Traceback (most recent call last):
File "/www/cocurate2_dev/startup.wsgi", line 3, in <module>
from django.core.wsgi import get_wsgi_application
File "/www/cocurate2_dev/components/lib/python2.7/site-packages/django/core/wsgi.py", line 2, in <module>
from django.core.handlers.wsgi import WSGIHandler
File "/www/cocurate2_dev/components/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 10, in <module>
from django import http
File "/www/cocurate2_dev/components/lib/python2.7/site-packages/django/http/__init__.py", line 5, in <module>
from django.http.response import (
File "/www/cocurate2_dev/components/lib/python2.7/site-packages/django/http/response.py", line 13, in <module>
from django.core.serializers.json import DjangoJSONEncoder
File "/www/cocurate2_dev/components/lib/python2.7/site-packages/django/core/serializers/__init__.py", line 23, in <module>
from django.core.serializers.base import SerializerDoesNotExist
File "/www/cocurate2_dev/components/lib/python2.7/site-packages/django/core/serializers/base.py", line 4, in <module>
from django.db import models
File "/www/cocurate2_dev/components/lib/python2.7/site-packages/django/db/models/__init__.py", line 4, in <module>
from django.db.models import signals # NOQA
ImportError: cannot import name signals
Everything works find when using manage.py runserver. I've updated the wsgi file to be the same as the default one from django 1.10.
I've checked that signals.py exists inside django, I've also cleaned .pyc files.
It turns out there actually was a file missing from the django installation for various reasons, it just wasn't signals.py but rather something it imported.
You can debug problems like this by running python with -v or -vv switch to make output verbose. I was able to see that it was trying to import another file from signals.py.
I had this error when my Django 1.10 install was downgraded to Django 1.6 by a third party.
After removing it and re-installing the correct version of Django, everything worked like a champ.
every time I tried to build a django project. I have no initialized files like manage.py in my project.
Then I tried to create the project on command line, I got this:
C:\Python34\Lib\site-packages\Django-1.9.3-py3.4.egg\django\bin> python .\django-admin.py startproject "MySite"
Traceback (most recent call last):
File ".\django-admin.py", line 2, in <module>
from django.core import management
File "C:\Python34\lib\site-packages\django-1.9.3-py3.4.egg\django\core\management\__init__.py", line 10, in <module>
from django.apps import apps
File "C:\Python34\lib\site-packages\django-1.9.3-py3.4.egg\django\apps\__init__.py", line 1, in <module>
from .config import AppConfig
File "C:\Python34\lib\site-packages\django-1.9.3-py3.4.egg\django\apps\config.py", line 6, in <module>
from django.utils.module_loading import module_has_submodule
File "C:\Python34\lib\site-packages\django-1.9.3-py3.4.egg\django\utils\module_loading.py", line 67, in <module>
from importlib.util import find_spec as importlib_find
ImportError: cannot import name 'find_spec'
Somebody could help me? I really appreciate your help.
ps: python3.4, django_1.9
U need to put your code here because it seems you are having too many import errors
You are trying to create a Django project from within your Python installation (C:\Python34\Lib\site-packages\Django-1.9.3-py3.4.egg\django\bin>).
Try going to your home directory and trying there. django-admin should be in C:\Python34\Scripts\ and that should be in your PATH so you should be able to call it from anywhere.
PS Use virtualenv
I'm working on flask project which is in python3.4, my project structure is like below,
|-- venv
|-- web
|--admin
|--settings
|--custom_settings.py
|--script.py
Here venv folder is python3 virtual env with flask & etc modules installed.
in script.py file, i am trying to import module from settings package as below,
from admin.settings.custom_settings import db, Role, Users
but when i try to execute the script i am getting error
user#mint ~/PRJ/web $ ../../venv/bin/python3 script.py
Traceback (most recent call last):
File "script.py", line 23, in <module>
from admin.settings.custom_settings import db, Role, User
File "/home/user/PRJ/web/admin/__init__.py", line 19, in <module>
admin.settings.custom_settings import db, Role, User
ImportError: No module named 'settings'
output from sys.path
/home/user/PRJ/admin/web
/home/user/PRJ/admin
/home/user/PRJ/venv/lib/python3.4
/home/user/PRJ/venv/lib/python3.4/plat-x86_64-linux-gnu
/home/user/PRJ/venv/lib/python3.4/lib-dynload
/usr/lib/python3.4
/usr/lib/python3.4/plat-x86_64-linux-gnu
/home/user/PRJ/venv/lib/python3.4/site-package
Please let me know what what I'm doing wrong here.
I'm following along with a Flask tutorial, and I'm creating a run.py file, running chmod a+x run.py, and running the file as ./run.py.
Unfortunately, I get this:
Traceback (most recent call last):
File "./run.py", line 3, in <module>
from app import app
File "/Users/benjaminclayman/Desktop/microblog/app/__init__.py", line 1, in <module>
from flask import Flask
ImportError: cannot import name Flask
For reference, my run.py file is:
#!flask/bin/python
from app import app
app.run(debug=True)
And when I run
from flask import Flask
there's no issue (I don't get any error message).
I looked at similar issues on SO and it looks like often it was having a file called flask.py but I don't have one (AFAIK).
Any idea what I did incorrectly?
Make your shebang
#!/usr/bin/env python
and run again. See this question.
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