gpt4 book ai didi

python - 导入错误 : cannot import name "urandom"

转载 作者:IT老高 更新时间:2023-10-28 20:52:38 27 4
gpt4 key购买 nike

当我在运行虚拟环境 (workon django1.2) 时尝试 runserver 我的任何项目时出现此错误

错误:

ImportError: cannot import name "urandom"

在研究了我发现的问题后 this :

Warning Python bugfix releases 2.6.8, 2.7.3, 3.1.5 and 3.2.3 include a change that will cause “import random” to fail with “cannot import name urandom” on any virtualenv created on a Unix host with an earlier release of Python 2.6/2.7/3.1/3.2, if the underlying system Python is upgraded. This is due to the fact that a virtualenv uses the system Python’s standard library but contains its own copy of the Python interpreter, so an upgrade to the system Python results in a mismatch between the version of the Python interpreter and the version of the standard library. It can be fixed by removing $ENV/bin/python and re-running virtualenv on the same target directory with the upgraded Python.

但是运行 ENV/bin/python 给了我:

bash: ENV/bin/python: No file or directory of this type

在哪里可以找到我的 virtualen 目录?

我对 virtualenvs 了解甚少,请多多包涵

谢谢

最佳答案

你必须重新创建你的虚拟环境。

我的猜测是发生了以下情况:

  1. 您创建了一个虚拟环境
  2. 在稍后的某个时间点,系统的 Python 安装更新了 urandom 安全错误修复。
  3. 您的 virtualenv(从以前的 Python 点版本创建)不再工作(由于您在问题中提到的问题)

最简单的解决方法是删除您的虚拟环境并创建一个新环境:

$ rm -r VIRTUALENVDIR
$ virtualenv VIRTUALENVDIR
$ . VIRTUALENVDIR/bin/activate

# then pip install any required packages, if your project has a requirements.txt file,
# this is simply:
$ pip install -r requirements.txt

# otherwise, you will have to install each package
$ pip install packagename
$ pip install packagename==version

关于python - 导入错误 : cannot import name "urandom",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13194308/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com