Windows系统上通过conda创建的全新的Python虚拟环境使用pip list查看依赖包列表,会发现已经安装了很多的包,但是打开site-packages文件夹查看,环境确实是新的,没有list里那些包,那说明是pip出了问题,把非虚拟环境的包也列出来了,我的Python版本是3.10,解决方法:
先运行如下命令:
python -m site --help
系统输出如下信息:
D:\python\marker\myenv\lib\site.py [--user-base] [--user-site]
Without arguments print some useful information
With arguments print the value of USER_BASE and/or USER_SITE separated
by ';'.
Exit codes with --user-base or --user-site:
0 - user site directory is enabled
1 - user site directory is disabled by user
2 - user site directory is disabled by super user
or for security reasons
>2 - unknown error
在你的虚拟环境文件夹中找到这个site.py文件,打开,在最开始的如下代码里:
import sys
import os
import builtins
import _sitebuiltins
import io
import stat
# Prefixes for site-packages; add additional prefixes like /usr/local here
PREFIXES = [sys.prefix, sys.exec_prefix]
# Enable per user site-packages directory
# set it to False to disable the feature or True to force the feature
ENABLE_USER_SITE = None
# for distutils.commands.install
# These values are initialized by the getuserbase() and getusersitepackages()
# functions, through the main() function when Python starts.
USER_SITE = None
USER_BASE = None
将ENABLE_USER_SITE = None的None修改为False,
ENABLE_USER_SITE = False
保存文件,重新在conda虚拟环境中运行pip list就可以看到当前环境实际安装的包了