我正在尝试使用布尔格式的值之一将字典写入 json 文件。当我尝试运行我的代码时出现以下错误。
raise TypeError(f'Object of type {o. class . name } ' TypeError: object of type bool_ is not JSON serializable
为此,我目前正在使用 Python。
我正在尝试运行一项使用简单变压器 Roberta 模型进行分类的服务。测试时,推理脚本/函数本身按预期工作。当我将其包含在快速 API 中时,它会关闭服务器。
\nuvicorn==0.11.8\nfastapi==0.61.1\nsimpletransformers==0.51.6\ncmd : uvicorn --host 0.0.0.0 --port 5000 src.main:app\nRun Code Online (Sandbox Code Playgroud)\n@app.get("/article_classify")\ndef classification(text:str):\n """function to classify article using a deep learning model.\n Returns:\n [type]: [description]\n """\n\n _,_,result = inference(text)\n return result\nRun Code Online (Sandbox Code Playgroud)\n错误 :
\nINFO: Started server process [8262]\nINFO: Waiting for application startup.\nINFO: Application startup complete.\nINFO: Uvicorn running on http://0.0.0.0:5000 (Press CTRL+C to quit)\nINFO: 127.0.0.1:36454 - "GET / HTTP/1.1" 200 OK\nINFO: 127.0.0.1:36454 - "GET /favicon.ico HTTP/1.1" 404 Not Found\nINFO: 127.0.0.1:36454 - "GET /docs HTTP/1.1" …Run Code Online (Sandbox Code Playgroud) python multilabel-classification fastapi uvicorn simpletransformers
Django 似乎没有找到我的主机0.0.0.0
我已经将“0.0.0.0”添加到我的 ALLOWED_HOSTS 中。事实上,如果我print(ALLOWED_HOSTS)得到了
['localhost', '127.0.0.1', '0.0.0.0', '[::1]']。我在码头工人工作。有什么我忽略的吗?
.env.dev
DEBUG=1
SECRET_KEY=foo
DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 0.0.0.0 [::1]
SQL_ENGINE=django.db.backends.postgresql
SQL_DATABASE=xxxx
SQL_USER=xxxx
SQL_PASSWORD=xxxx
SQL_HOST=db
SQL_PORT=5432
DATABASE=postgres
Run Code Online (Sandbox Code Playgroud)
env_settings.py
import os
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get("SECRET_KEY")
# SECURITY WARNING: don't run with debug turned on in production!
# DEBUG = True
DEBUG = int(os.environ.get("DEBUG", default=0))
ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS").split(" ")
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) …Run Code Online (Sandbox Code Playgroud) 我正在阅读python 文档并偶然发现以下几行:
同样重要的是要注意,作为类实例属性的用户定义函数不会转换为绑定方法;这只发生在函数是类的属性时。
请有人用简单的英语解释这意味着什么。
我将介绍一些速记符号:
让“用户定义函数”由f表示,
让“类实例”由ci表示,而类仅由c表示。显然(?), ci = c(), 有一些符号滥用。
此外,允许成员声明以简单的集合表示法重铸,例如“作为类实例属性的用户定义函数”的简写是“ vf: f?a(ci) ”,其中v : ' for all ' 和 where ' a ' 是(一组)属性(例如类或类实例的)和 '?' 的简写 表示集合隶属函数。
此外,绑定函数的过程通过 ci.f(*args) 或 cf(*args) => f(ci, *args) 或 f(c, *args)(前者指的是实例方法调用而后者指的是类方法调用)
使用新引入的速记符号,文档中的引用是否暗示
vf: f?a(c), cf(*args) => f(c, *args) 是一个真实的陈述
尽管
vf: f?a(ci), ci.f(*args) => f(ci, *args) 是假的?
每次我关闭 VSCode(在运行一些 Python 脚本之后)时,我都会有一个 Python 任务在我的 M1 MacBook Air 上运行 90-100% CPU 的终端中徘徊,我每次都必须手动终止它。我在 PID 上运行了以下命令:
ps aux | grep <PID>
Run Code Online (Sandbox Code Playgroud)
它每次都返回相同的东西......
Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/Resources/Python.app/Contents/MacOS/Python /Users/<user>/.vscode/extensions/ms-python.python-2021.2.625869727/pythonFiles/runJediLanguageServer.py
Run Code Online (Sandbox Code Playgroud)
我检查了我的 VSCode 扩展,我没有安装任何“绝地”扩展,但也许它是其他扩展的一个挥之不去的任务。任何想法如何解决这一问题?
当我使用时pipreqs,我遇到了这个问题。我使用 anaconda 和俄语 Windows。
root@DESKTOP-ETLLRI1 C:\Users\root\Desktop\resumes
$ pipreqs C:\Users\root\Desktop\resumes
Traceback (most recent call last):
File "C:\Users\root\Anaconda3\Scripts\pipreqs-script.py", line 9, in <module>
sys.exit(main())
File "C:\Users\root\Anaconda3\lib\site-packages\pipreqs\pipreqs.py", line 396, in main
init(args)
File "C:\Users\root\Anaconda3\lib\site-packages\pipreqs\pipreqs.py", line 341, in init
extra_ignore_dirs=extra_ignore_dirs)
File "C:\Users\root\Anaconda3\lib\site-packages\pipreqs\pipreqs.py", line 75, in get_all_imports
contents = f.read()
File "C:\Users\root\Anaconda3\lib\encodings\cp1251.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 1206: character maps to <undefined>
Run Code Online (Sandbox Code Playgroud) mypy 报告以下代码中的错误:
import enum
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Enum
Base = declarative_base()
class MyEnum(enum.Enum):
A = 1
B = 2
class MyTable(Base):
__tablename__ = 'my_table'
col = Column(Enum(MyEnum), nullable=False)
c = MyTable(col=MyEnum.A)
Run Code Online (Sandbox Code Playgroud)
以下是错误:
a.py:16: 错误:“MyTable”的“col”类型不兼容(得到“MyEnum”,预期“str”)
如何在不添加“type:ignore”的情况下消除此错误?我还可以将 MyEnum.A 替换为 MyEnum.A.name 以使错误消失。但这看起来并不干净,并且 sqlalchemy 文档中也没有建议。
!mkdir -p '{FRAME_OUTPUT_DIR}'
%cd /home/jovyan/project/DAIN
!MKL_THREADING_LAYER=AMD
!python -W ignore colab_interpolate.py --netName DAIN_slowmotion --time_step {fps/TARGET_FPS} --start_frame 1 --end_frame {frame_count} --frame_input_dir '{FRAME_INPUT_DIR}' --frame_output_dir '{FRAME_OUTPUT_DIR}'
Run Code Online (Sandbox Code Playgroud)
输出这个...
我尝试将 FORCE 设置为 1 但没有任何反应,输出然后就消失了......
/home/jovyan/project/DAIN
Error: mkl-service + Intel(R) MKL: MKL_THREADING_LAYER=INTEL is incompatible with libgomp.so.1 library.
Try to import numpy first or set the threading layer accordingly. Set MKL_SERVICE_FORCE_INTEL to force it.```
Hey there, can anyone help me solve this problem with DAIN? I'm using Saturn Cloud with pytorch but it outputs this...
Run Code Online (Sandbox Code Playgroud) 给定一个像这样的 SQLAlchemy ORM 模型
class Foo(Base):
__tablename__ = 'foo'
id = sa.Column(sa.Integer, primary_key=True)
name = sa.Column(sa.String())
Run Code Online (Sandbox Code Playgroud)
在 SQLAlchemy 1.4 / 2.0 中,ORM 的session.query习惯用法正在与 SQLAlchemy 核心select函数*统一,因此要获取所有Foo我们会做的
foos = session.execute(Foo).scalars().all()
Run Code Online (Sandbox Code Playgroud)
代替
foos = session.query(Foo).all()
Run Code Online (Sandbox Code Playgroud)
在当前 (sqlalchemy<=1.3) ORM 中,我们可以Foo通过以下查询获取数据库中s的数量:
nfoos = session.query(Foo).count()
Run Code Online (Sandbox Code Playgroud)
但是我们如何在 SQLALchemy 1.4 中获得计数呢?
session.execute(sa.select(Foo).count())
Run Code Online (Sandbox Code Playgroud)
加注
AttributeError: 'Select' 对象没有属性 'count'
session.execute(sa.select(Foo)).count()
Run Code Online (Sandbox Code Playgroud)
加注
AttributeError: 'ChunkedIteratorResult' 对象没有属性 'count'
session.execute(sa.select(sa.func.count(Foo)))
Run Code Online (Sandbox Code Playgroud)
加注
sqlalchemy.exc.ArgumentError: SQL 表达式元素预期,得到
<class '__main__.Foo'>。
这有效,
session.execute(sa.select(sa.func.count(Foo.id))).scalars()
Run Code Online (Sandbox Code Playgroud)
但是指定一个属性似乎没有Query.count版本那么 OO / 优雅。此外,它排除了构建查询但推迟决定是检索计数还是模型实例的可能性。
count() …
当尝试使用SQLAlchemy v1.4.15 中的方法NotImplementedError: This method is not implemented for SQLAlchemy 2.0.删除表时,我收到一个, 。delete
from sqlalchemy import Column, Integer, MetaData, String, Table, create_engine, delete
engine = create_engine("sqlite+pysqlite:///:memory:", echo=True, future=True)
metadata = MetaData()
user = Table(
"users", metadata, Column("id", Integer, primary_key=True), Column("name", String)
)
metadata.create_all(engine)
engine.execute(user.delete()) # leading to Traceback
# NotImplementedError: This method is not implemented for SQLAlchemy 2.0.
Run Code Online (Sandbox Code Playgroud) python ×10
sqlalchemy ×3
anaconda ×1
django ×1
fastapi ×1
json ×1
mypy ×1
numpy ×1
python-3.x ×1
python-jedi ×1
uvicorn ×1