SQLAutoCode - error when attempting to generate schema - python

I'm trying to auto generate a schema for use in SQLalchemy, I'm using sqlautocode to do this, I use the following command
D:~ admin$ sqlautocode mysql://'user':"pass"#xx.xx.xx.xx:3306/db_name -o tables.py
but I keep getting the following error..
Traceback (most recent call last):
File "/usr/local/bin/sqlautocode", line 9, in <module>
load_entry_point('sqlautocode==0.7', 'console_scripts', 'sqlautocode')()
File "/Library/Python/2.7/site-packages/distribute-0.6.45-py2.7.egg/pkg_resources.py", line 343, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/Library/Python/2.7/site-packages/distribute-0.6.45-py2.7.egg/pkg_resources.py", line 2354, in load_entry_point
return ep.load()
File "/Library/Python/2.7/site-packages/distribute-0.6.45-py2.7.egg/pkg_resources.py", line 2060, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/Library/Python/2.7/site-packages/sqlautocode/main.py", line 4, in <module>
from declarative import ModelFactory
File "/Library/Python/2.7/site-packages/sqlautocode/declarative.py", line 17, in <module>
from sqlalchemy.ext.declarative import _deferred_relation as _deferred_relationship
ImportError: cannot import name _deferred_relation
https://pypi.python.org/pypi/sqlautocode

Use sqlacodegen instead:
D:~ admin$ sqlacodegen mysql://'users':"pass"#xx.xx.xx.xx:3306/db_name --outfile tables.py

this is because you sqlalchemy version is above 07.
find declarative.py in C:\Python27\Lib\site-packages\sqlautocode
change from sqlalchemy.ext.declarative import _deferred_relationship To
from sqlalchemy.ext.declarative.clsregistry import _deferred_relationship
this work in my work.

Related

Thonny py5-mode Error when running a code

I just tried to use py5 in thonny, but everytime i have the py5 mode on and try to run a code i get a bunch of error messeges, i dont really know what they mean so maybe somebody can help me out ?
thanks in advance
This is the error im always getting
Traceback (most recent call last):
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\py5_tools\tools\run_sketch.py", line 52, in <module>
main()
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\py5_tools\tools\run_sketch.py", line 44, in main
imported.run_code(
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\py5_tools\imported.py", line 135, in run_code
_run_code(
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\py5_tools\imported.py", line 259, in _run_code
_run_sketch(sketch_path, classpath, exit_if_error)
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\py5_tools\imported.py", line 196, in _run_sketch
import py5
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\py5\__init__.py", line 84, in <module>
from py5_tools.magics import load_ipython_extension # noqa
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\py5_tools\magics\__init__.py", line 22, in <module>
from .drawing import DrawingMagics, DXFDrawingMagic
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\py5_tools\magics\drawing.py", line 27, in <module>
from IPython.display import display, SVG, Image
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\IPython\__init__.py", line 51, in <module>
from .core.application import Application
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\IPython\core\application.py", line 26, in <module>
from IPython.core import release, crashhandler
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\IPython\core\crashhandler.py", line 27, in <module>
from IPython.core import ultratb
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\IPython\core\ultratb.py", line 101, in <module>
import stack_data
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\stack_data\__init__.py", line 1, in <module>
from .core import Source, FrameInfo, markers_from_ranges, Options, LINE_GAP, Line, Variable, RangeInLine, \
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\stack_data\core.py", line 19, in <module>
from stack_data.utils import (
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\stack_data\utils.py", line 11, in <module>
from asttokens import ASTText
ImportError: cannot import name 'ASTText' from 'asttokens' (C:\Users\schwe\AppData\Local\Programs\Thonny\lib\site-packages\asttokens\__init__.py)
I received a response from the py5 developer via Github. They also provided an explanation but it goes over my head, something about "The Python library asttokens is used for parsing syntax trees and syntax highlighting. It is not used by py5 but it might be used by Jupyter Notebook and/or JupyterLab.". They also provided a solution here:
enter link description here

Unable to Import Spacy or Download Models

I recently tried to install the spaCy module for Python 3.7. The installation looks like it runs successfully (shows no errors), but when I try to import spaCy, or when I try to install spaCy models, I get the error below. I'm totally lost; please help!
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\mjrei\AppData\Local\Programs\Python\Python37\lib\site-packages\spacy\__init__.py", line 14, in <module>
from . import pipeline # noqa: F401
File "C:\Users\mjrei\AppData\Local\Programs\Python\Python37\lib\site-packages\spacy\pipeline\__init__.py", line 1, in <module>
from .attributeruler import AttributeRuler
File "C:\Users\mjrei\AppData\Local\Programs\Python\Python37\lib\site-packages\spacy\pipeline\attributeruler.py", line 6, in <module>
from .pipe import Pipe
File "spacy\pipeline\pipe.pyx", line 1, in init spacy.pipeline.pipe
File "spacy\strings.pyx", line 15, in init spacy.strings
File "C:\Users\mjrei\AppData\Local\Programs\Python\Python37\lib\site-packages\spacy\util.py", line 1635, in <module>
default_error_handler: Callable[[str, "Pipe", List["Doc"], Exception], NoReturn],
File "C:\Users\mjrei\AppData\Local\Programs\Python\Python37\lib\typing.py", line 755, in __getitem__
return self.__getitem_inner__(params)
File "C:\Users\mjrei\AppData\Local\Programs\Python\Python37\lib\typing.py", line 251, in inner
return func(*args, **kwds)
File "C:\Users\mjrei\AppData\Local\Programs\Python\Python37\lib\typing.py", line 774, in __getitem_inner__
result = _type_check(result, msg)
File "C:\Users\mjrei\AppData\Local\Programs\Python\Python37\lib\typing.py", line 135, in _type_check
raise TypeError(f"Plain {arg} is not valid as type argument")
TypeError: Plain typing.NoReturn is not valid as type argument

Flask(flask db init): AttributeError: module 'time' has no attribute 'clock'

While following a Flask tutorial I stumbled around this very strange problem! While setting up the Migrate directory , after the first step of setting the flask app using set FLASK_APP=sql1.py, when I ran this command flask db init I got this error:
(first_flask_env) C:\Users\aakash\Desktop\python programs>flask db init
Traceback (most recent call last):
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\aakash\Anaconda3\envs\first_flask_env\Scripts\flask.exe\__main__.py", line 7, in <module>
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\flask\cli.py", line 894, in main
cli.main(args=args, prog_name=name)
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\flask\cli.py", line 557, in main
return super(FlaskGroup, self).main(*args, **kwargs)
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\click\core.py", line 697, in main
rv = self.invoke(ctx)
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\click\core.py", line 1061, in invoke
cmd_name, cmd, args = self.resolve_command(ctx, args)
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\click\core.py", line 1100, in resolve_command
cmd = self.get_command(ctx, cmd_name)
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\flask\cli.py", line 500, in get_command
self._load_plugin_commands()
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\flask\cli.py", line 496, in _load_plugin_commands
self.add_command(ep.load(), ep.name)
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\pkg_resources\__init__.py", line 2472, in load
return self.resolve()
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\pkg_resources\__init__.py", line 2478, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\flask_migrate\__init__.py", line 8, in <module>
from alembic import __version__ as __alembic_version__
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\alembic\__init__.py", line 8, in <module>
from . import op # noqa
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\alembic\op.py", line 1, in <module>
from .operations.base import Operations
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\alembic\operations\__init__.py", line 1, in <module>
from .base import Operations, BatchOperations
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\alembic\operations\base.py", line 3, in <module>
from .. import util
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\alembic\util\__init__.py", line 6, in <module>
from .pyfiles import ( # noqa
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\alembic\util\pyfiles.py", line 6, in <module>
from mako.template import Template
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\mako\template.py", line 10, in <module>
from mako.lexer import Lexer
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\mako\lexer.py", line 11, in <module>
from mako import parsetree, exceptions, compat
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\mako\parsetree.py", line 9, in <module>
from mako import exceptions, ast, util, filters, compat
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\mako\exceptions.py", line 11, in <module>
from mako import util, compat
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\mako\util.py", line 11, in <module>
from mako import compat
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\mako\compat.py", line 124, in <module>
time_func = time.clock
AttributeError: module 'time' has no attribute 'clock'
I'm getting the exact same error while running my .py script also,here's the script:
from flask import Flask
import os
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
basedir = os.path.abspath(os.path.dirname(__file__)) #Full directory path of the file I'm working with..here, sql1.py
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'data.sqlite')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
Migrate(app,db) #Here it connect the application "app.py"
# with the database "db"
class puppy(db.Model):
__tablename__ = 'Name Provided by me!!'
id = db.Column(db.Integer,primary_key = True)
name = db.Column(db.Text)
age = db.Column(db.Integer)
def __init__(self,name,age):
self.name = name
self.age = age
def __repr__(self):
return f"puppy {self.name} is {self.age} year/s old!"
I looked into every solution I found (here and this)and made sure everything was correct! I ran this command when my environment was activated which had installed every package needed including SQLAlchemy and Flask-Migrate.
I even deleted them (packages) and re-installed their latest versions but still getting the same error!
I'm using Python 3.8.5
You have some dependencies that are too old and incompatible with Python 3.8. At the very least, you should update the mako package:
pip install --upgrade mako
I had a similar issue I had to update flask_sqlalchemy even after doing this I had issues. I ended up having to make a new virtual environment, I would make a small hello world project on another virtual environment to see if that works.
For me, it was giving the same error, so I removed __init__.py file from the folder which has app.py
After removing I ran the
flask init db
it worked :)

Importing a resource file

I'm having trouble removing a resource file in a pyqt document, I'm also using monkeystudio IDE. I madea program with images and all linked to a resource file called "resources.qyc" and now I get the error
Traceback (most recent call last):
File "main.py", line 9, in <module>
from Login import Login
File "J:\Newone\Login.py", line 3, in <module>
import mainwindow
File "J:\Newone\mainwindow.py", line 2, in <module>
import Addcadet
File "J:\Newone\Addcadet.py", line 6, in <module>
( Ui_Addcadet, QDialog ) = uic.loadUiType( 'Addcadet.ui' )
File "C:\Python32\lib\site-packages\PyQt4\uic\__init__.py", line 203, in loadUiType
exec(code_string.getvalue(), ui_globals)
File "<string>", line 179, in <module>
ImportError: No module named resources_rc
You'll first have to compile the resource file using pyrcc4. You'll run something like this from command line:
pyrcc4 ResourceFile.qrc -o ui_ResourceFile.py

Python: Impossible to import mktime in Eclipse: ImportError

If I import pgdb just in command line, it works fine.
It was also working fine in Eclipse until recently (with exactly the same Python 2.7.2), but now, when I import pgdb, even in a very simple file (containing just import pgdb), I have this error message:
Traceback (most recent call last):
File ".../src/pgdbtest.py", line 8, in <module>
import pgdb
File "build/bdist.macosx-10.6-x86_64/egg/pgdb.py", line 66, in <module>
File "build/bdist.macosx-10.6-x86_64/egg/_pg.py", line 7, in <module>
File "build/bdist.macosx-10.6-x86_64/egg/_pg.py", line 4, in __bootstrap__
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pkg_resources.py", line 908, in resource_filename
self, resource_name
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pkg_resources.py", line 1383, in get_resource_filename
self._extract_resource(manager, self._eager_to_zip(name))
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pkg_resources.py", line 1401, in _extract_resource
timestamp = time.mktime(date_time)
AttributeError: 'module' object has no attribute 'mktime'
In fact, more generally, I discovered that if I try from time import mktime, I also have error:
from time import mktime
ImportError: cannot import name mktime
OK, stupid mistake: I created a package named "time"...
So I just deleted it and everything is alright now.

Categories

Resources