python脚本环境搭建问题总结

2023-05-16

问题:Command "/usr/bin/python3 -u -c "import setuptools

Command “/usr/bin/python3 -u -c “import setuptools, tokenize;file=‘/tmp/pip-build-oa36vb2k/numpy/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-eiwtp2f2-record/install-record.txt --single-version-externally-managed --compile --user --prefix=” failed with error code 1 in /tmp/pip-build-oa36vb2k/numpy/
在这里插入图片描述
解决办法:
python3 -m pip install --upgrade pip

问题:ImportError: cannot import name ‘_AES’ from ‘Crypto.Cipher’

ImportError: cannot import name ‘_AES’ from ‘Crypto.Cipher’
解决办法:

python3 -m pip install pycryptodome

问题:No module named ‘jira’

解决

使用python 3.7环境执行命令

python3.7  -m pip install jira

问题:AttributeError: type object ‘datetime.datetime’ has no attribute ‘fromisoformat’

【解决方案1】:
这里的问题实际上是 fromisoformat 在 Python 3.7 之前的版本中不可用,您可以在文档 here 中看到明确说明。

Return a date corresponding to a date_string given in the format YYYY-MM-DD:
from datetime import date
date.fromisoformat('2019-12-04')
datetime.date(2019, 12, 4)

This is the inverse of date.isoformat(). It only supports the format YYYY-MM-DD.

New in version 3.7.

【解决方案2】:
我遇到了同样的问题,发现了这个:

https://pypi.org/project/backports-datetime-fromisoformat/

 from datetime import date, datetime, time
 from backports.datetime_fromisoformat import MonkeyPatch
MonkeyPatch.patch_fromisoformat()

 datetime.fromisoformat("2014-01-09T21:48:00-05:30")
datetime.datetime(2014, 1, 9, 21, 48, tzinfo=-05:30)

 date.fromisoformat("2014-01-09")
datetime.date(2014, 1, 9)

 time.fromisoformat("21:48:00-05:30")
datetime.time(21, 48, tzinfo=-05:30)

【讨论】:

效果很好,但是datetime.datetime 中是否有类似timedelta 的功能。你怎么能在这里增加日期?
它的工作方式与您预期的一样。由于您仍然导入 datetime 并仅更新 fromisoformat 其余部分保持不变。

问题:如何安装多个python环境

解决
一、查看python版本

python3 -V

这一步如果我用python -V会显示没有装python,用python2 -V会显示没有装python2。

二、安装python3.7

sudo apt-get install python3.7

三、使用update-alternatives管理软件版本
update-alternatives用于在多个同功能的软件,或软件的多个不同版本间选择。
1、将python3.6和python3.7添加到update-alternatives:

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2

2、更新python3的指向(选择python3执行的是python3.7还是python3.6)

sudo update-alternatives --config python3

3、查看python版本

python3 -V
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

python脚本环境搭建问题总结 的相关文章

随机推荐