Copying the import lines from tap.py...
tap.py:
import site
import user
from site import security, agent
from site.security import models
When I run this i am getting:
File "/home/vikasadmin/user/tap.py", line 31, in init
from site import security, agent
File "/usr/lib/python2.6/site-packages/site/security.py", line 9, in <module>
from site import models
File "/usr/lib/python2.6/site-packages/site/models.py", line 12, in <module>
from site import config
ImportError: cannot import name config
Since I already imported models from site.security this config should have been included. Please explain? How can I solve this?
Related
I was trying to run some python code in docker and export a .csv file to S3, but got the same error as in aiobotocore - ImportError: cannot import name 'InvalidIMDSEndpointError' (asking here because I don't have enough reputation to comment under that thread..)
File "/opt/conda/lib/python3.7/site-packages/s3fs/__init__.py", line 1, in <module>
from .core import S3FileSystem, S3File
File "/opt/conda/lib/python3.7/site-packages/s3fs/core.py", line 14, in <module>
import aiobotocore
File "/opt/conda/lib/python3.7/site-packages/aiobotocore/__init__.py", line 1, in <module>
from .session import get_session, AioSession
File "/opt/conda/lib/python3.7/site-packages/aiobotocore/session.py", line 6, in <module>
from .client import AioClientCreator, AioBaseClient
File "/opt/conda/lib/python3.7/site-packages/aiobotocore/client.py", line 12, in <module>
from .utils import AioS3RegionRedirector
File "/opt/conda/lib/python3.7/site-packages/aiobotocore/utils.py", line 10, in <module>
from botocore.exceptions import (
ImportError: cannot import name 'InvalidIMDSEndpointError' from 'botocore.exceptions' (/opt/conda/lib/python3.7/site-packages/botocore/exceptions.py)
I tried to use the versions of libraries as in the comment:
botocore==1.19.52
s3fs==0.5.1
boto3==1.16.52
aiobotocore==1.2.0
However, these don't solve the problem and I still get the same error.
Could anyone here give me some hints how to solve this?
Thanks!
Ok, I can answer my own question :)
Just install s3fs, and it will take care of version dependencies of other libraries..
New to programming and followed this course: https://www.youtube.com/watch?v=4F2m91eKmts&feature=emb_logo
When things went to Webscraping, got errors:
Code says:
import requests
from bs4 import BeautifulSoup
page = requests.get('https://forecast.weather.gov/MapClick.php?lat=34.05349000000007&lon=-118.24531999999999')
soup = BeautifulSoup(page.content, 'html.parser')
print(soup.find_all('a'))
Return is:
File "/Users/.../python/cleverprogrammer/webscraping.py", line 1, in
import requests File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/requests/init.py",
line 112, in
from . import utils File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/requests/utils.py",
line 26, in
from ._internal_utils import to_native_string File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/requests/_internal_utils.py",
line 11, in
from .compat import is_py2, builtin_str, str File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/requests/compat.py",
line 59, in
from http import cookiejar as cookielib File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/cookiejar.py",
line 39, in
from calendar import timegm ImportError: cannot import name 'timegm' from 'calendar'
(/Users/.../python/cleverprogrammer/calendar.py)
Is there some problem with the way Requests are installed? Maybe use of pipenv is not the correct way?
And why does it call for calendar.py file and 'timegm'? Calendar.py is different file from the same course, in same folder.
What are the steps, that I can take, to get rid of these messages and get working Requests?
Thanks in advance.
I'm trying to use iohub to incorporate Eye-Tracking (SR-research Eye-Link) support in my experiment in Psychopy.
I'm using python2.7 on a Mac.
However, I get an error while I'm trying to import it:
from psychopy.iohub.datastore.util import ExperimentDataAccessUtility
File "/Users/.../ETUtilities.py", line 2, in <module>
from psychopy.iohub.datastore.util import ExperimentDataAccessUtility
File "/Library/Python/2.7/site-packages/PsychoPy-1.82.01-py2.7.egg/psychopy/iohub/datastore/__init__.py", line 16, in <module>
import tables
File "/Library/Python/2.7/site-packages/tables/__init__.py", line 90, in <module>
from .utilsextension import (
ImportError: cannot import name get_pytables_version
I tried to install this module but found nothing.
Any idea?
You mean you didn't find the module?
https://www.google.com/search?source=hp&ei=bGw7WtaDCMbDgAb6qo3gAw&q=pytables&oq=pytables&gs_l=psy-ab.3..35i39k1l2j0l8.592.592.0.784.2.1.0.0.0.0.125.125.0j1.1.0.crnk_dmh...0...1.2.64.psy-ab..1.1.124.0...0.LZUJpfdZBYE
I have the following project structure:
./app/__init__.py
./app/main/__init__.py
./app/main/views.py
./app/models.py
./app/resources/__init__.py
./app/resources/changesAPI.py
./config.py
./manage.py
The app/models.py file has the following line:
from app import db
db is defined in app/__init__.py
db = SQLAlchemy()
I'm importing classes from models.py from app/resources/__init__.py:
from app.models import User, Task, TaskChange, Revision
However, it fails when model tries to import db:
Traceback (most recent call last):
File "manage.py", line 5, in <module>
from app import create_app, db, api
File "/Users/nahuel/proj/ptcp/app/__init__.py", line 16, in <module>
from app.resources.changesAPI import ChangesAPI
File "/Users/nahuel/proj/ptcp/app/resources/__init__.py", line 5, in <module>
from app.models import User, Task, TaskChange, Revision
File "/Users/nahuel/proj/ptcp/app/models.py", line 1, in <module>
from app import db
ImportError: cannot import name db
What am I doing wrong?
You have a circular import.
You are importing create_app, db and api from manage.py, which triggers an import of the app.resources.changesAPI module, which in turn then triggers import of the __init__.py package in app/resources which then tries to import your models, which fails because db was not yet defined in app/__init__.py.
You need to move importing ChangesAPI to after the line that defines db in your app/__init__.py file. Any name defined in app/__init__.py before the from app.resources.changesAPI import ChangesAPI is available to your sub-packages, names after are not.
I am trying to bundle django with cx_freeze. With my setup.py I am able to bundle it together but when I invoke the generated executable I get the below import error. I have tried various ways to fix this but unable to get a way around.
Versions used:
Django==1.6.4
cx-Freeze==4.3.3
./build/exe.linux-x86_64-2.7/script
Traceback (most recent call last):
File "lib/python2.7/site-packages/cx_Freeze/initscripts/Console.py", line 27, in <module>
exec(code, m.__dict__)
File "script.py", line 7, in <module>
from models import Project
File "/remote/vgrnd77/pritam/tryout/package/models.py", line 6, in <module>
from django.db.models import CharField, Model, \
File "lib/python2.7/site-packages/django/db/models/__init__.py", line 5, in <module>
from django.db.models.query import Q
File "lib/python2.7/site-packages/django/db/models/query.py", line 14, in <module>
from django.db.models.fields import AutoField
File "lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 15, in <module>
from django import forms
File "lib/python2.7/site-packages/django/forms/__init__.py", line 8, in <module>
from django.forms.fields import *
File "lib/python2.7/site-packages/django/forms/fields.py", line 17, in <module>
from django.forms.util import ErrorList, from_current_timezone, to_current_timezone
File "lib/python2.7/site-packages/django/forms/util.py", line 4, in <module>
from django.utils.html import format_html, format_html_join
File "lib/python2.7/site-packages/django/utils/html.py", line 12, in <module>
from django.utils.text import normalize_newlines
File "lib/python2.7/site-packages/django/utils/text.py", line 11, in <module>
from django.utils.six.moves import html_entities
ImportError: cannot import name html_entities
Here is my sample script:
#!/usr/bin/env python
import os
import django
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from models import Project
if __name__ == '__main__':
print "My first exe"
p = Project.objects.all()
for project in p:
print project.name
Here is how the setup.py looks like:
main_python_file = "script.py"
import sys
from cx_Freeze import setup, Executable
# html_entities is missing
base = 'Console'
buildOptions = dict(
create_shared_zip = False,
append_script_to_exe = False,
packages = [],
includes = ['django'],
excludes = ['tkinter']
)
setup(
name = "my_exe",
version = "0.1",
description = "My first exe",
options = dict(build_exe = buildOptions),
executables = [Executable(main_python_file, base = base)])
Here is how the project table looks like:
class Project(Model):
"""
Project table
"""
name = CharField(max_length=255)
Has anyone faced and solved this ?
Freeze Output shows it was not able to figure out django.utils.six.moves. It shows 'six' in missing modules:
Missing modules:
? django.utils.six.moves imported from django.db.backends, django.db.models.base, django.db.models.sql.where, django.dispatch.dispatcher, django.forms.formsets, django.http.cookie, django.http.response, django.utils.crypto, django.utils.functional, django.utils.html_parser, django.utils.ipv6, django.utils.regex_helper, django.utils.text
? django.utils.six.moves.urllib.parse imported from django.core.files.storage, django.core.validators, django.forms.fields, django.forms.widgets, django.http.request, django.http.response, django.utils.encoding, django.utils.html, django.utils.http
If you look in the django.utils.six file you will find the following code:
...
MovedModule("http_cookiejar", "cookielib", "http.cookiejar"),
MovedModule("http_cookies", "Cookie", "http.cookies"),
MovedModule("html_entities", "htmlentitydefs", "html.entities"),
MovedModule("html_parser", "HTMLParser", "html.parser"),
...
What django does dynamically is build up the django.utils.six.moves module out of thin air. The parameters to MovedModule are . So the solution in python33 (the one I used) is to import html.entities in my Executable module. I tried to add it to the includes for the executable, but that didn't seem to work. I assume you could use the import htmlenditydefs for the python2 version.