pyrhon中安装django和在cmd中安装django有啥区别?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pyrhon中安装django和在cmd中安装django有啥区别?相关的知识,希望对你有一定的参考价值。

参考技术A

在cmd里用pip安装django会配置到环境变量path中,而且还会配置适合的版本。

但直接下载django就会出现一些问题,比如调用不了一些命令像django-admin startproject mysite

所以建议使用pip安装。

在 django 项目中安装 mysqlclient 时出错

【中文标题】在 django 项目中安装 mysqlclient 时出错【英文标题】:Error while installing mysqlclient in django project 【发布时间】:2019-05-04 05:46:05 【问题描述】:

这几天我一直在尝试解决这个问题。 我正在尝试在虚拟环境中制作一个 django 项目并在其上安装 mysqlclient。 过程是这样的: 在我的项目路径中:

virtualenv pyvenv1

然后我激活了它:

source /pyvenv1/bin/activate

然后我安装了django:

pip install django

然后我做了一个新项目:

django-admin startproject djangop1

然后在那个项目中我尝试安装 mysqlclient

pip install mysqlclient

我回来了:

    Collecting mysqlclient
  Using cached https://files.pythonhosted.org/packages/ec/fd/83329b9d3e14f7344d1cb31f128e6dbba70c5975c9e57896815dbb1988ad/mysqlclient-1.3.13.tar.gz
Building wheels for collected packages: mysqlclient
  Running setup.py bdist_wheel for mysqlclient ... error
  Complete output from command /Users/daniel/Documents/Python/DjangoP1/py1/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/1h/dg482p2x2bz7n46_px8nphf40000gn/T/pip-install-xgahev5_/mysqlclient/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 /private/var/folders/1h/dg482p2x2bz7n46_px8nphf40000gn/T/pip-wheel-4_cp0769 --python-tag cp37:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.9-x86_64-3.7
  copying _mysql_exceptions.py -> build/lib.macosx-10.9-x86_64-3.7
  creating build/lib.macosx-10.9-x86_64-3.7/MySQLdb
  copying MySQLdb/__init__.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
  copying MySQLdb/compat.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
  copying MySQLdb/connections.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
  copying MySQLdb/converters.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
  copying MySQLdb/cursors.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
  copying MySQLdb/release.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
  copying MySQLdb/times.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
  creating build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
  copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
  copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
  copying MySQLdb/constants/CR.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
  copying MySQLdb/constants/ER.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
  copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
  copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
  copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
  running build_ext
  building '_mysql' extension
  creating build/temp.macosx-10.9-x86_64-3.7
  gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -Dversion_info=(1,3,13,'final',0) -D__version__=1.3.13 -I/usr/local/Cellar/mysql-connector-c/6.1.11/include -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c _mysql.c -o build/temp.macosx-10.9-x86_64-3.7/_mysql.o
  _mysql.c:257:6: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                          s = PyUnicode_AsUTF8(item);
                            ^ ~~~~~~~~~~~~~~~~~~~~~~
  _mysql.c:287:6: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                          s = PyUnicode_AsUTF8(item);
                            ^ ~~~~~~~~~~~~~~~~~~~~~~
  _mysql.c:564:3: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                  _stringsuck(ca, value, ssl);
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  _mysql.c:553:16: note: expanded from macro '_stringsuck'
          if(t)d=PyUnicode_AsUTF8(t);ssl_keepref[n_ssl_keepref++]=t;\
                 ^~~~~~~~~~~~~~~~~~~~
  _mysql.c:565:3: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                  _stringsuck(capath, value, ssl);
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  _mysql.c:553:16: note: expanded from macro '_stringsuck'
          if(t)d=PyUnicode_AsUTF8(t);ssl_keepref[n_ssl_keepref++]=t;\
                 ^~~~~~~~~~~~~~~~~~~~
  _mysql.c:566:3: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                  _stringsuck(cert, value, ssl);
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  _mysql.c:553:16: note: expanded from macro '_stringsuck'
          if(t)d=PyUnicode_AsUTF8(t);ssl_keepref[n_ssl_keepref++]=t;\
                 ^~~~~~~~~~~~~~~~~~~~
  _mysql.c:567:3: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                  _stringsuck(key, value, ssl);
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
  _mysql.c:553:16: note: expanded from macro '_stringsuck'
          if(t)d=PyUnicode_AsUTF8(t);ssl_keepref[n_ssl_keepref++]=t;\
                 ^~~~~~~~~~~~~~~~~~~~
  _mysql.c:568:3: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                  _stringsuck(cipher, value, ssl);
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  _mysql.c:553:16: note: expanded from macro '_stringsuck'
          if(t)d=PyUnicode_AsUTF8(t);ssl_keepref[n_ssl_keepref++]=t;\
                 ^~~~~~~~~~~~~~~~~~~~
  _mysql.c:2530:8: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
          cname = PyUnicode_AsUTF8(name);
                ^ ~~~~~~~~~~~~~~~~~~~~~~
  8 warnings generated.
  gcc -bundle -undefined dynamic_lookup -arch x86_64 -g build/temp.macosx-10.9-x86_64-3.7/_mysql.o -L/usr/local/Cellar/mysql-connector-c/6.1.11/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.9-x86_64-3.7/_mysql.cpython-37m-darwin.so
  ld: library not found for -lssl
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  error: command 'gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for mysqlclient
  Running setup.py clean for mysqlclient
Failed to build mysqlclient
Installing collected packages: mysqlclient
  Running setup.py install for mysqlclient ... error
    Complete output from command /Users/daniel/Documents/Python/DjangoP1/py1/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/1h/dg482p2x2bz7n46_px8nphf40000gn/T/pip-install-xgahev5_/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 /private/var/folders/1h/dg482p2x2bz7n46_px8nphf40000gn/T/pip-record-fnk1xc7q/install-record.txt --single-version-externally-managed --compile --install-headers /Users/daniel/Documents/Python/DjangoP1/py1/bin/../include/site/python3.7/mysqlclient:
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.9-x86_64-3.7
    copying _mysql_exceptions.py -> build/lib.macosx-10.9-x86_64-3.7
    creating build/lib.macosx-10.9-x86_64-3.7/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
    copying MySQLdb/compat.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
    copying MySQLdb/connections.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
    copying MySQLdb/converters.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
    copying MySQLdb/release.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
    copying MySQLdb/times.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
    creating build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
    copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
    running build_ext
    building '_mysql' extension
    creating build/temp.macosx-10.9-x86_64-3.7
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -Dversion_info=(1,3,13,'final',0) -D__version__=1.3.13 -I/usr/local/Cellar/mysql-connector-c/6.1.11/include -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c _mysql.c -o build/temp.macosx-10.9-x86_64-3.7/_mysql.o
    _mysql.c:257:6: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                            s = PyUnicode_AsUTF8(item);
                              ^ ~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:287:6: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                            s = PyUnicode_AsUTF8(item);
                              ^ ~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:564:3: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                    _stringsuck(ca, value, ssl);
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:553:16: note: expanded from macro '_stringsuck'
            if(t)d=PyUnicode_AsUTF8(t);ssl_keepref[n_ssl_keepref++]=t;\
                   ^~~~~~~~~~~~~~~~~~~~
    _mysql.c:565:3: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                    _stringsuck(capath, value, ssl);
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:553:16: note: expanded from macro '_stringsuck'
            if(t)d=PyUnicode_AsUTF8(t);ssl_keepref[n_ssl_keepref++]=t;\
                   ^~~~~~~~~~~~~~~~~~~~
    _mysql.c:566:3: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                    _stringsuck(cert, value, ssl);
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:553:16: note: expanded from macro '_stringsuck'
            if(t)d=PyUnicode_AsUTF8(t);ssl_keepref[n_ssl_keepref++]=t;\
                   ^~~~~~~~~~~~~~~~~~~~
    _mysql.c:567:3: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                    _stringsuck(key, value, ssl);
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:553:16: note: expanded from macro '_stringsuck'
            if(t)d=PyUnicode_AsUTF8(t);ssl_keepref[n_ssl_keepref++]=t;\
                   ^~~~~~~~~~~~~~~~~~~~
    _mysql.c:568:3: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                    _stringsuck(cipher, value, ssl);
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:553:16: note: expanded from macro '_stringsuck'
            if(t)d=PyUnicode_AsUTF8(t);ssl_keepref[n_ssl_keepref++]=t;\
                   ^~~~~~~~~~~~~~~~~~~~
    _mysql.c:2530:8: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
            cname = PyUnicode_AsUTF8(name);
                  ^ ~~~~~~~~~~~~~~~~~~~~~~
    8 warnings generated.
    gcc -bundle -undefined dynamic_lookup -arch x86_64 -g build/temp.macosx-10.9-x86_64-3.7/_mysql.o -L/usr/local/Cellar/mysql-connector-c/6.1.11/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.9-x86_64-3.7/_mysql.cpython-37m-darwin.so
    ld: library not found for -lssl
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
Command "/Users/daniel/Documents/Python/DjangoP1/py1/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/1h/dg482p2x2bz7n46_px8nphf40000gn/T/pip-install-xgahev5_/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 /private/var/folders/1h/dg482p2x2bz7n46_px8nphf40000gn/T/pip-record-fnk1xc7q/install-record.txt --single-version-externally-managed --compile --install-headers /Users/daniel/Documents/Python/DjangoP1/py1/bin/../include/site/python3.7/mysqlclient" failed with error code 1 in /private/var/folders/1h/dg482p2x2bz7n46_px8nphf40000gn/T/pip-install-xgahev5_/mysqlclient/

在 mysqlclient 文档中,它说我首先需要做:

brew install mysql-connector-c

然后编辑mysql_config

我都做了。

我的 $PATH:

/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

我也使用 brew 安装了 gcc,同样的错误。

我很迷茫,任何帮助将不胜感激。

谢谢!

【问题讨论】:

错误编码在ld: library not found for -lssl行中。可能您缺少 openssl 库;尝试brew install openssl 解决这个问题。 Error installing mysql-python: library not found for -lssl的可能重复 ***.com/… 我尝试安装openssl,它说它已经安装了。但是,它还告诉我设置变量(CPPFLAGS 和 LDFLAGS),在我这样做之后它就起作用了!非常感谢!! 【参考方案1】:

更新:

所以基本上我需要运行这些行来安装 mysqlclient:

brew install openssl
export CPPFLAGS="-I/usr/local/opt/openssl/include"
export LDFLAGS="-L/usr/local/opt/openssl/lib"

【讨论】:

【参考方案2】:

/usr/bin/ld: 找不到-lssl

/usr/bin/ld: 找不到-lcrypto

如果你找到上面的行然后使用这个命令 sudo apt-get install libssl-dev

【讨论】:

【参考方案3】:

如果你没有安装mysql_config,就会抛出错误,这种情况下使用下面的命令。

sudo apt install libmysqlclient-dev

希望这能解决问题。

【讨论】:

以上是关于pyrhon中安装django和在cmd中安装django有啥区别?的主要内容,如果未能解决你的问题,请参考以下文章

在 PyCharm 中安装 Django [重复]

centos 安装教程 服务器配置教程 服务器中安装python 服务器中安装Django

在 python django 服务 ubuntu 中安装 reportLab

在 virtualenv 中安装 Django:MySQL-python 错误

想在 Ubuntu 中安装 Django [重复]

django 环境搭建