- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我是 django 的新手,我创建了一个网站,现在我处于部署阶段,一切都运行良好,直到启动从数据库到服务器的迁移。我会向你展示我从一开始所做的一切
OC_project8/
pur_beurre/
catalog/
dumps/
catalog.json
... # other classic file
media/
pur_beurre/
static/
.gitignore
... # other classic file
static/
templates/
users/
manage.py
Procfile
venv/
requirements.txt/
certifi==2019.9.11
chardet==3.0.4
coverage==4.5.4
dj-database-url==0.5.0
Django==2.2.6
django-debug-toolbar==2.0
gunicorn==19.9.0
idna==2.8
mysqlclient==1.4.4
Pillow==6.2.0
pytz==2019.3
requests==2.22.0
sqlparse==0.3.0
urllib3==1.25.6
whitenoise==4.1.4
.gitignore/
所有命令都在虚拟环境中运行,例如:
(venv) ~/OC_project8/pur_beurre$ sudo apt-get install python-psycopg2
我在运行命令 git push heroku master 之前完成了所有必要的步骤(git commit, heroku create my-app ...)如果您需要有关这些步骤的更多详细信息,请告诉我。
运行命令 git push heroku master 后我遇到了这个错误:
....
remote: Collecting pkg-resources==0.0.0 (from -r /tmp/build_cac68f54540915062647a425c52dc61b/requirements.txt (line 11))
remote: Could not find a version that satisfies the requirement pkg-resources==0.0.0 (from -r/tmp/build_cac68f54540915062647a425c52dc61b/requirements.txt (line 11)) (from versions: )
remote: No matching distribution found for pkg-resources==0.0.0 (from -r /tmp/build_cac68f54540915062647a425c52dc61b/requirements.txt (line 11))
remote: ! Push rejected, failed to compile Python app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to pur-beurre-oc8.
remote:
To https://git.heroku.com/pur-beurre-oc8.git
! [remote rejected] master -> master (pre-receive hook declined)
error: impossible de pousser des références vers 'https://git.heroku.com/pur-beurre-oc8.git'
我在 stackoverflow 中看到我必须这样做:
pip uninstall pkg-resources==0.0.0
在我提交之后:
git add requirements.txt
git commit -m "uninstalling pkg-resources==0.0.0"
现在 git push heroku master
工作正常,但是当我访问我的网站时出现错误:应用程序错误
。我不知道我是否被弄湿了,但我想是因为我还没有完成数据库的迁移。
所以我运行命令 heroku run python pur_beurre/manage.py migrate
现在我遇到了这个错误:
Running python pur_beurre/manage.py migrate on ⬢ pur-beurre-oc8... up, run.4138 (Free)
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 20, in <module>
import psycopg2 as Database
ModuleNotFoundError: No module named 'psycopg2'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "pur_beurre/manage.py", line 21, in <module>
main()
File "pur_beurre/manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute
django.setup()
File "/app/.heroku/python/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/app/.heroku/python/lib/python3.6/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/app/.heroku/python/lib/python3.6/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/auth/models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/base.py", line 117, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/base.py", line 321, in add_to_class
value.contribute_to_class(cls, name)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/options.py", line 204, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/__init__.py", line 28, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py", line 201, in __getitem__
backend = load_backend(db['ENGINE'])
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py", line 110, in load_backend
return import_module('%s.base' % backend_name)
File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 24, in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named 'psycopg2'
我不知道为什么会出现此错误,因为 psycopg2 是使用 PostgreSQL 所需的库,而我正在使用 MySQL,这是我的 settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'openfoodfacts',
'USER': 'root',
'PASSWORD': 'my-password',
'HOST': '',
'PORT': '5432',
}
}
在出现此错误后,无论如何我都尝试安装 psycopg2:
pip install psycopg2
但是我有另一个错误:
Collecting psycopg2
Downloading https://files.pythonhosted.org/ packages/84/d7/6a93c99b5ba4d4d22daa3928b983cec66df4 536ca50b22ce5dcac65e4e71/psycopg2-2.8.4.tar.gz (377kB)
100% |████████████████████████████████| 378kB 1.8MB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/rouizi/OC_project8/venv/lib/python3.6/site-packages/setuptools/__init__.py", line 12, in <module>
import setuptools.version
File "/home/rouizi/OC_project8/venv/lib/python3.6/site-packages/setuptools/version.py", line 1, in <module>
import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-gf4fxs4k/psycopg2/
可能是因为我卸载了才出现这个错误一开始是 pkg-resources !但是我尝试重新安装 pkg-resources:
sudo apt-get install --reinstall python-pkg-resources
然后我重新运行命令pip install psycopg2
,但仍然有同样的错误
通过在谷歌上搜索我在这里找到了No module named pkg_resources有必要运行此命令:
wget https://bootstrap.pypa.io/ez_setup.py -O - | python
然后我重新运行命令 pip install psycopg2
,但出现另一个错误:
Collecting psycopg2
Using cached https://files.pythonhosted.org/ packages/84/d7/6a93c99b5ba4d4d22daa3928b983cec66df 4536ca50b22ce5dcac65e4e71/psycopg2-2.8.4.tar.gz
Complete output from command python setup.py egg_info:
running egg_info
creating pip-egg-info/psycopg2.egg-info
writing pip-egg-info/psycopg2.egg-info/PKG-INFO
writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt
writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt
writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'
Error: pg_config executable not found.
pg_config is required to build psycopg2 from source. Please add the directory
containing pg_config to the $PATH or specify the full executable path with the
option:
python setup.py build_ext --pg-config /path/to/pg_config build ...
or with the pg_config option in 'setup.cfg'.
If you prefer to avoid building psycopg2 from source, please install the PyPI
'psycopg2-binary' package instead.
For further information please check the 'doc/src/install.rst' file (also at
<http://initd.org/psycopg/docs/install.html>).
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-sglmdb2o/psycopg2/
如果我运行命令 which pg_config
它什么都不返回,但经过一些研究我喜欢这里 pg_config executable not found有必要运行此命令:
sudo apt-get install libpq-dev
现在 which pg_config
返回这个:
/usr/bin/pg_config
所以我重新运行 pip install psycopg2
并且发生了另一个错误:
Collecting psycopg2
Using cached https://files.pythonhosted.org/ packages/84/d7/6a93c99b5ba4d4d22 daa3928b983cec66df4536ca50b22ce5dcac65e4e71/psycopg2-2.8.4.tar.gz
Building wheels for collected packages: psycopg2
Running setup.py bdist_wheel for psycopg2 ... error
Complete output from command /home/rouizi/OC_project8/venv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-lu4ihs81/psycopg2/setup.py';f=getattr(tokenize,
'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmphgjf714ppip-wheel- --python-tag cp36:
usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: -c --help [cmd1 cmd2 ...]
or: -c --help-commands
or: -c cmd --help
error: invalid command 'bdist_wheel'
----------------------------------------
Failed building wheel for psycopg2
Running setup.py clean for psycopg2
Failed to build psycopg2
Installing collected packages: psycopg2
Running setup.py install for psycopg2 ... error
#I cut here because it's very long
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-lu4ihs81/psycopg2/setup.py", line 611, in <module>
'Documentation': 'http://initd.org/psycopg/docs/',
File "/home/rouizi/OC_project8/venv/lib/python3.6/site-packages/setuptools/__init__.py", line 129, in setup
return distutils.core.setup(**attrs)
File "/usr/lib/python3.6/distutils/core.py", line 148, in setup
dist.run_commands()
File "/usr/lib/python3.6/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/home/rouizi/OC_project8/venv/lib/python3.6/site-packages/setuptools/command/install.py", line 61, in run
return orig.install.run(self)
File "/usr/lib/python3.6/distutils/command/install.py", line 601, in run
self.run_command(cmd_name)
File "/usr/lib/python3.6/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/home/rouizi/OC_project8/venv/lib/python3.6/site-packages/setuptools/command/install_scripts.py", line 17, in run
import setuptools.command.easy_install as ei
File "/home/rouizi/OC_project8/venv/lib/python3.6/site-packages/setuptools/command/easy_install.py", line 47, in <module>
from setuptools.sandbox import run_setup
File "/home/rouizi/OC_project8/venv/lib/python3.6/site-packages/setuptools/sandbox.py", line 15, in <module>
import pkg_resources.py31compat
ModuleNotFoundError: No module named 'pkg_resources.py31compat'
----------------------------------------
Command "/home/rouizi/OC_project8/venv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-lu4ihs81/psycopg2/setup.py';f=getattr(tokenize, 'open', open)(__file__)
;code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-eya3xv3b-record/install-record.txt --single-version-externally-managed
--compile --install-headers /home/rouizi/OC_project8/venv/include/site/python3.6/psycopg2" failed with error code 1 in /tmp/pip-build-lu4ihs81/psycopg2/
我试过这个命令:
sudo apt-get install --reinstall python-setuptools
现在,当我尝试运行 pip install psycopg2
时,他返回给我:
Requirement already satisfied: psycopg2 in /home/rouizi/OC_project8/venv/lib/python3.6/site-packages
但是如果我尝试运行命令 heroku run python pur_beurre/manage.py migrate
我仍然有错误:
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named 'psycopg2'
但如果我运行 sudo apt-get install python-psycopg2
它有效,但在运行 heroku run python pur_beurre/manage.py migrate
时我仍然遇到错误由于我仍然有同样的错误,所以我尝试卸载 psycopg2:
sudo pip uninstall psycopg2
但它返回给我:
The directory '/home/rouizi/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Not uninstalling psycopg2 at /usr/lib/python2.7/dist-packages, outside environment /usr
然后卡了一天没找到解决办法,希望大家帮忙
抱歉,帖子太长,拼错了
最佳答案
我解决了我的问题!我运行命令 pip install psycopg2
,它返回给我错误:
ModuleNotFoundError: No module named 'pkg_resources.py31compat'
但是如果我尝试重新运行命令 pip install psycopg2
,它会显示:
Requirement already satisfied: psycopg2 in /home/rouizi/OC_project8/venv/lib/python3.6/site-packages
所以我试着提交我的更改:
pip freeze > requirements.txt
git add requirements.txt
git commit -m "installing psycopg2"
git push heroku master
现在 heroku run python pur_beurre/manage.py migrate
工作正常。
我不知道为什么,因为我出错了,如果有人能解释一下就好了
关于python - Django:启动迁移到 heroku 时没有名为 'psycopg2' 的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58650554/
目前,我正在尝试配置 Django 以在项目中使用,并且在尝试运行 python manage.py syncdb 时遇到持续错误。 File "/x/x/x/x/x/x/base.py", line
sqlite 的 Python db-api 实现有一个方便的方法 executescript() 来执行多语句 SQL 脚本。它对于创建数据库非常有用。参见 sqlite driver docume
我有一个时间戳,我正在尝试使用 psycopg 将其插入到 postgres 中,但我无法解决问题,我认为这是因为我正在尝试使用 python 的字符串格式将日期放入正确的位置。我有这样的东西 val
我试图生成一些有效的 Postgresql 语句,但是 cursor.execute 方法以一种奇怪的方式解释我的参数。 这是我的代码切割: for key in data_dict.keys():
我在尝试插入数据库时遇到了问题: ur_psql.execute("""insert into smth(data, filedate, filedby)""" "
已结束。此问题不符合 Stack Overflow guidelines .它目前不接受答案。 关闭 9 年前。 有关您编写的代码问题的问题必须在问题本身中描述具体问题——并包含有效代码以重现它。见
我们使用一个对象来保持与 PostgreSQL 数据库的连接并创建新的游标来处理请求。我观察到奇怪的行为:即使读取响应并关闭游标,请求仍然卡在数据库中,阻止更新表等。 当连接关闭时,它就消失了。 我了
我在更改我的 postgres 数据库中的表时遇到了一些问题。我正在使用 psycopg2 并使用 Python。我试图添加一个串行主键。它花了很长时间(大表),并且没有抛出任何错误,所以它做了一些事
当使用 psycopg 连接到 postgresql 数据库时,我拉了网线,没有出现任何错误。我如何在代码中检测到这一点以通知用户? 最佳答案 psycopg 无法检测到网络发生了什么。例如,如果您拔
我不断收到这个 error: psycopg2.ProgrammingError: column "someentry" does not exist. 当 someentry 不是列时,错误表明 s
我是 python 的初学者。我们使用这段代码来执行 SQL 命令。 cur.execute("INSERT INTO test (num, data) VALUES (%s, %s)", (100,
我正在处理 Udacity 的在线项目。我正在使用他们配置的 vagrant 来运行包含数据库的服务器。不幸的是,当我试图赋予代码持久性时,服务器每次都会返回错误。我是 python 的新手,所以请原
我用psycopg2创建数据库失败,语法错误,但在前几行使用相同的语法是行得通的,为什么要问?两行代码,为什么是第二行语法错误? [代码] db_name = 'series_id' self._cu
这个问题在这里已经有了答案: ValueError: operation parameter must be str or unicode (1 个回答) 关闭 4 年前。 我最近修改了我的插入查询
如何修复 Python 中的 SQL 语句? 数据库连接有效。但是,cur.execute 返回 none,这是错误的。 我的代码 import os, pg, sys, re, psycopg2 t
我正在尝试运行这样的代码: query = "copy (select email from my_table) TO 'STDOUT' WITH (FORMAT csv, DELIMITER '|
在 OSX Mojave 上安装了 Python3 和 Postgres 11.3,运行 pip install psycopg2 并收到以下冗长的错误消息。 据我所知,满足 psycopg 的要求,
有没有办法让 psycopg 和 postgres 无需重新建立连接就可以处理错误,比如 MySQLdb?下面的注释版本适用于 MySQLdb,注释使其适用于 Psycopg2: results =
我收到了一个来自野外的 unicode 字符串,它导致我们的一些 psycopg2 语句失败。 我已将问题简化为 SSCE: import psycopg2 conn = psycopg2.conne
我正在尝试在 Windows(Windows 7、64 位)下安装 psycopg2。我正在使用 Python 2.7.2 from Python(x,y)和 PostgreSQL 9.2.1。 我的
我是一名优秀的程序员,十分优秀!