Python常见问题

使用了与模块相同的命名

AttributeError: module ‘psutil’ has no attribute ‘cpu_times’

可能在项目中有 psutil.py 的文件

使用了与函数相同的命名

AttributeError: partially initialized module ‘os’ has no attribute ‘stat’ (most likely due to a circular import)

可能在项目中有 stat.py 的文件

Python模块安装失败

Try to run this command from the system terminal. Make sure that you use the correct version of ‘pip’ installed for your Python interpreter located at ‘D:\development\Python_3.8.5\Scripts\python.exe’.

在这里插入图片描述
在这里插入图片描述
pycharm虚拟环境与python解释器,pip版本要一致

可以直接安装到pycharm虚拟环境,不修改安装目录:

# 如安装pymysql到pycharm虚拟环境
pip install pymysql --target=D:\development\Python_3.8.5\Lib\site-packages

以管理员身份运行pycharm,或者cmd

# 阿里镜像
pip install torch==1.7.1 -i https://mirrors.aliyun.com/pypi/simple/
# 安装指定版本pip安装包
python -m pip install pip==22.2.2
# 查看可更新的安装包
pip list -o

在这里插入图片描述

# 更新版本
pip install -U pip

在这里插入图片描述

Cannot find reference ‘dom’ in ‘init.pyi’

在这里插入图片描述
我们Ctrl+左键进入__init__.py发现是有dom成员的

在这里插入图片描述
所以这个编译错误可以忽略

虚拟环境出现问题

ImportError: Couldn’t import Django. Are you sure it’s installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?

我把Django安装到虚拟环境,没有在\venv3.8.5\Lib\site-packages\bin发现django-admin.exe文件。我也不知道为什么。

解决:重新创建了虚拟环境,安装Django后就正常了。

Django端口被占用

[WinError 10013]以一种访问权限不允许的方式做了一个访问套接字的尝试

Django创建用户失败

django.db.utils.OperationalError: no such table: auth_user

1、首先使用命令行创建默认库

python manage.py migrate

2、使用命令行创建默认超级用户:

python manage.py createsuperuser

Python3.9安装mysqlclient失败(痛!太痛了!)

Preparing metadata (setup.py) … error
error: subprocess-exited-with-error

× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [16 lines of output]
/bin/sh: mysql_config: command not found
/bin/sh: mariadb_config: command not found
/bin/sh: mysql_config: command not found

由于我的mysql在docker中,缺少了mysql_config配置文件。

尝试安装mysqlclient-2.1.1.tar.gz,结果一样,失败。

尝试拷贝mysqlclient-2.1.1-py3.9.egg-info到我site-packages中,启动项目后报Did you install mysqlclient?

解决方法一(推荐):切换使用pymysql

这个就需要在你的Django子应用app的__init__.py中加入:

import pymysql
pymysql.install_as_MySQLdb()  # 使用pymysql代替mysqldb连接数据库

我比较喜欢pymysql,因为我不想在本地安装mysql。

解决方法二:将mysql安装到本地来解决,不然要安装什么mysql-connector-c不仅浪费内存,还很很鸡肋。

查看:Homebrew安装mysql

# 查看 mysql_config 路径
whereis mysql_config

django生成数据库表失败

Running migrations:
No migrations to apply.

我将生成的数据库表和0001_initial.py删除后重新执行命令,就会出现这样的问题。

解决:将django_migrations表中有关那张表的数据删除,重新执行命令。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

愛沢かりん

感谢您对我的支持

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值