首页 > 解决方案 > 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

可能的原因:

  1. 我最近在“C:\Program Files\Python38”中以管理员身份(适用于所有用户)重新安装了 Python 3.8.2,当我以管理员身份登录计算机并通过控制台运行代码时,上述代码有效。(在以用户身份安装 pip 后,我以管理员身份安装了 numpy)

  2. 接下来,我首先通过安装有问题的包/库并收到警告:

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
  1. 我试过添加:

    'C:\Users\cqqkie\AppData\Roaming\Python\Python38\Scripts'
    'C:\Program Files\Python38\Scripts'
    'C:\Users\cqqkie\AppData\Local\Programs\Python\Python38-32'

    到我的系统变量以及环境变量中的用户变量。

它不起作用,此时我很困惑。这里似乎有什么问题?

标签: pythonpython-3.xwindowspathpip

解决方案


推荐阅读