python - Python 目录、pip 和新库的问题
问题描述
我在 Windows10 x64(通过控制台或 Pycharm)上运行 Python 程序时遇到问题,因为我已经通过控制台上的 pip 安装了 numpy、django、wheel 等。不幸的是,我无法确定错误消息的开头或结尾。
例如运行(在 Windows Powershell 中):
PS C:\Users\cqqkie> python
Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\cqqkie\AppData\Roaming\Python\Python38\site-packages\numpy\__init__.py", line 140, in <module>
from . import _distributor_init
File "C:\Users\cqqkie\AppData\Roaming\Python\Python38\site-packages\numpy\_distributor_init.py", line 26, in <module>
WinDLL(os.path.abspath(filename))
File "C:\Program Files\Python38\lib\ctypes\__init__.py", line 373, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 is not a valid Win32 application
>>>
>>> x = np.array([[1, 2, 3], [4, 5, 6]])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'np' is not defined
可能的原因:
我最近在“C:\Program Files\Python38”中以管理员身份(适用于所有用户)重新安装了 Python 3.8.2,当我以管理员身份登录计算机并通过控制台运行代码时,上述代码有效。(在以用户身份安装 pip 后,我以管理员身份安装了 numpy)
接下来,我首先通过安装有问题的包/库并收到警告:
C:\Users\cqqkie>pip install wheel <br />
Defaulting to user installation because normal site-packages is not writeable
Collecting wheel Using cached wheel-0.34.2-py2.py3-none-any.whl (26 kB)
Installing collected packages: wheel WARNING: The script wheel.exe is installed
in 'C:\Users\cqqkie\AppData\Roaming\Python\Python38\Scripts' which is not on
PATH.
Consider adding this directory to PATH or, if you prefer to suppress this
warning, use --no-warn-script-location.
Successfully installed wheel-0.34.2
我试过添加:
'C:\Users\cqqkie\AppData\Roaming\Python\Python38\Scripts'
'C:\Program Files\Python38\Scripts'
'C:\Users\cqqkie\AppData\Local\Programs\Python\Python38-32'到我的系统变量以及环境变量中的用户变量。
它不起作用,此时我很困惑。这里似乎有什么问题?
解决方案
推荐阅读
- mongodb - 如何在mongodb中使用查询和分组
- c++ - 如何使用 3 个按钮对 Arduino 菜单进行编程?
- python-3.x - AttributeError:“KerasTPUModel”对象没有属性“_ckpt_saved_epoch”
- r - 如何创建一个函数来比较数据集中列中的值并返回数据集中其他列的值
- c# - Modbus 功能 0x06
- java - 使用自定义 AuthenticationFailureHandler 时为 302 而不是 200
- python - 如何将属性添加到现有图表
- azure-service-fabric - 在多个 Azure 区域中的 ServiceFabric 上运行微服务
- php - 如何使用 PHP 从文件中查找多行?
- git - Git 使用单个命令添加所有未暂存/未跟踪的文件