[英]Install python 3.6 mysqlclient for Django project on CentOS
我已經在CentOS 6.9上成功安裝了Django項目。 我已經在使用python3.6創建的虛擬環境中安裝了該項目python3.6 -m venv env
我已經激活了虛擬環境,現在我嘗試使用來運行該應用程序;
python manage.py runserver 0.0.0.0:8000
當我運行此命令時,出現以下錯誤;
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f7f7c5d67b8>
Traceback (most recent call last):
File "/REMOVED/REMOVED/python3.6/env/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 26, in <module>
import MySQLdb as Database
ModuleNotFoundError: No module named 'MySQLdb'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/REMOVED/REMOVED/python3.6/env/lib/python3.6/site-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/REMOVED/REMOVED/python3.6/env/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
autoreload.raise_last_exception()
File "/REMOVED/REMOVED/python3.6/env/lib/python3.6/site-packages/django/utils/autoreload.py", line 251, in raise_last_exception
six.reraise(*_exception)
File "/REMOVED/REMOVED/python3.6/env/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/REMOVED/REMOVED/python3.6/env/lib/python3.6/site-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/REMOVED/REMOVED/python3.6/env/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/REMOVED/REMOVED/python3.6/env/lib/python3.6/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models()
File "/REMOVED/REMOVED/python3.6/env/lib/python3.6/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "/REMOVED/REMOVED/python3.6/softwareix/storefront/models.py", line 10, in <module>
class Brand(models.Model):
File "/REMOVED/REMOVED/python3.6/env/lib/python3.6/site-packages/django/db/models/base.py", line 124, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/REMOVED/REMOVED/python3.6/env/lib/python3.6/site-packages/django/db/models/base.py", line 331, in add_to_class
value.contribute_to_class(cls, name)
File "/REMOVED/REMOVED/python3.6/env/lib/python3.6/site-packages/django/db/models/options.py", line 214, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/REMOVED/REMOVED/python3.6/env/lib/python3.6/site-packages/django/db/__init__.py", line 33, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/REMOVED/REMOVED/python3.6/env/lib/python3.6/site-packages/django/db/utils.py", line 211, in __getitem__
backend = load_backend(db['ENGINE'])
File "/REMOVED/REMOVED/python3.6/env/lib/python3.6/site-packages/django/db/utils.py", line 115, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "/REMOVED/REMOVED/python3.6/env/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 30, in <module>
'Did you install mysqlclient or MySQL-python?' % e
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'.
Did you install mysqlclient or MySQL-python?
我看到我缺少Python mysql擴展或驅動程序。 我試圖按照建議安裝它。 當我跑步時 pip install mysqlclient
我得到;
Collecting mysqlclient
Using cached mysqlclient-1.3.10.tar.gz
Installing collected packages: mysqlclient
Running setup.py install for mysqlclient ... error
Complete output from command /REMOVED/REMOVED/python3.6/env/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-7g3likz_/mysqlclient/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-y1mak800-record/install-record.txt --single-version-externally-managed --compile --install-headers /REMOVED/REMOVED/python3.6/env/include/site/python3.6/mysqlclient:
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.6
copying _mysql_exceptions.py -> build/lib.linux-x86_64-3.6
creating build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/__init__.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/compat.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/connections.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/converters.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/cursors.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/release.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/times.py -> build/lib.linux-x86_64-3.6/MySQLdb
creating build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
running build_ext
building '_mysql' extension
creating build/temp.linux-x86_64-3.6
gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,3,10,'final',0) -D__version__=1.3.10 -I/usr/include/mysql -I/REMOVED/REMOVED/python3.6/env/include -I/usr/local/include/python3.6m -c _mysql.c -o build/temp.linux-x86_64-3.6/_mysql.o
gcc: error trying to exec 'as': execvp: Permission denied
error: command 'gcc' failed with exit status 1
----------------------------------------
Command "/REMOVED/REMOVED/python3.6/env/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-7g3likz_/mysqlclient/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-y1mak800-record/install-record.txt --single-version-externally-managed --compile --install-headers /REMOVED/REMOVED/python3.6/env/include/site/python3.6/mysqlclient" failed with error code 1 in /tmp/pip-build-7g3likz_/mysqlclient/
這似乎不起作用。 搜索互聯網后,我嘗試使用yum安裝多個軟件包。 我嘗試安裝yum install python3-devel
但這不可用( No package python3-devel available.
可用的No package python3-devel available.
),我看到它應該在epel信息庫中。 所以我做了yum search python dev
,我明白了;
dbus-python-devel.x86_64 : Libraries and headers for dbus-python
gstreamer-python-devel.x86_64 : Headers for developing programs that will use gstreamer-python
libimobiledevice-python.x86_64 : Python bindings for libimobiledevice
pyldb-devel.x86_64 : Development files for the Python bindings for the LDB library
python-behave.noarch : Tools for the behavior-driven development, Python style
python-cherrypy.noarch : Pythonic, object-oriented web development framework
python-cherrypy2.noarch : Pythonic, object-oriented web development framework
python-devel.x86_64 : The libraries and header files needed for Python development
python-devel.i686 : The libraries and header files needed for Python development
python-igraph-devel.x86_64 : Development files for igraph
python-imaging-devel.x86_64 : Development files for python-imaging
python-mozdevice.noarch : Mozilla-authored device management
python-pyblock.x86_64 : Python modules for dealing with block devices
python-pyldns.x86_64 : Header files, libraries and development documentation for ldns.
python-pyside-devel.i686 : Development files for python-pyside
python-pyside-devel.x86_64 : Development files for python-pyside
python-tools.x86_64 : A collection of development tools included with Python
python34-devel.i686 : Libraries and header files needed for Python 3 development
python34-devel.x86_64 : Libraries and header files needed for Python 3 development
wxPython-devel.i686 : Development files for wxPython add-on modules
wxPython-devel.x86_64 : Development files for wxPython add-on modules
python-pycxx-devel.noarch : PyCXX header and source files
到目前為止,這是我嘗試過的。 我正在嘗試讓我的Django應用程序在MySQL上運行,但是擴展名或模塊似乎未安裝。
gcc: error trying to exec 'as': execvp: Permission denied
的gcc: error trying to exec 'as': execvp: Permission denied
診斷非常清楚。 使用which as
驗證您沒有在$PATH
上放置另一個名為as
文件。 您希望可以成功地編譯一個簡單的hello.c
Hello World程序,該程序涉及gcc
生成匯編代碼,並將as
轉換為intel x86目標代碼。 嘗試這個:
sudo yum install gcc binutils-devel
通過運行which as; as --version
驗證是否成功which as; as --version
which as; as --version
並看到一個橫幅,例如“ GNU匯編器(適用於Ubuntu的GNU Binutils)2.27”。
您當前沒有權限pip install mysqlclient
。 由於這是centos,因此您可能不想使用pip
(除非您設置了virtualenv
)。 您想運行yum install mysql-python
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.