Python

设置pip源

pip每次WARNING: Ignoring invalid distribution -andas 解决

问题过程:
(at38risk4) PS D:\codePython\GitlabRepos\at-documents> pip list|findstr "rqalpha api pandas numpy"
WARNING: Ignoring invalid distribution -andas (c:\users\cat\appdata\roaming\python\python38\site-packages)
WARNING: Ignoring invalid distribution -andas (c:\users\cat\appdata\roaming\python\python38\site-packages)
WARNING: Ignoring invalid distribution -andas (c:\users\cat\appdata\roaming\python\python38\site-packages)
market-data-python-api 2.3.9
numpy                  1.23.0
pandas                 1.0.3
rqalpha                6.0.5
rqalpha-mod-pyspec     2.8.17

解决:
(at38risk4) PS D:\codePython\GitlabRepos\at-documents> cd c:\users\cat\appdata\roaming\python\python38\site-packages
(at38risk4) PS C:\users\cat\appdata\roaming\python\python38\site-packages> dir ~*
    目录: C:\Users\cat\AppData\Roaming\Python\Python38\site-packages

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----         2023/3/30     09:53                ~andas
d-----         2023/3/30     09:53                ~andas-1.5.3.dist-info
d-----         2023/3/22     11:24                ~umpy

(at38risk4) PS C:\users\cat\appdata\roaming\python\python38\site-packages> rmdir ~*
C:\users\cat\appdata\roaming\python\python38\site-packages\~andas 处的项具有子项,并且未指定 Recurse 参数。如果继续,所有子项均将随该项删除。是否确实要继续?
C:\users\cat\appdata\roaming\python\python38\site-packages\~andas-1.5.3.dist-info 处的项具有子项,并且未指定 Recurse 参数。如果继续,所有子项均将随该项删除。是否确实要继续?
[Y] 是(Y)  [A] 全是(A)  [N] 否(N)  [L] 全否(L)  [S] 暂停(S)  [?] 帮助 (默认值为“Y”): Y
C:\users\cat\appdata\roaming\python\python38\site-packages\~umpy 处的项具有子项,并且未指定 Recurse 参数。如果继续,所有子项均将随该项删除。是否确实要继续?
[Y] 是(Y)  [A] 全是(A)  [N] 否(N)  [L] 全否(L)  [S] 暂停(S)  [?] 帮助 (默认值为“Y”): Y
(at38risk4) PS C:\users\cat\appdata\roaming\python\python38\site-packages> pip list|findstr andas
pandas                 1.0.3

virtualenv管理多环境

  • 存在形态
    pycharm客户端:interpreter-local-virtualenv
    物理文件夹
  • 查看环境列表
    在硬盘目录下,无激活概念,pycharm选择使用后,可进激活环境的终端
  • 创建venv
    直接用pycharm客户端,创建local virtualenv
  • 删除env
    删除文件夹和pycharm的环境项

pip包管理

  • 查看包源构成:python -m site
  • 查看包信息:pip show setuptools
  • pip清除缓存: pip cache purge
  • 升级pip包:python -m pip install pip==23.0
  • 升级setup包:python -m pip install setuptools==41.6.0
  • pip安装包(安装到python环境):pip install ffn
  • pip安装包(安装到系统用户共享python环境):pip install ffn --user
  • pip安装包(从指定的镜像源安装): pip install ffn -i https://pypi.tuna.tsinghua.edu.cn/simple/
  • pip安装wheel包:pip install resources/whl/TA_Lib-0.4.19-cp37-cp37m-win_amd64.whl
  • pip安装tar包:pip install resources/tar/TA_Lib-0.4.19-cp37-cp37m-win_amd64.tar
  • pip安装git源码:pip install git+https://github.com/bollwyvl/nb-mermaid.git@103502e6
卸载失败的解决事例
(quant3810) PS C:\Users\cat> pip uninstall -y pyzmq
WARNING: No metadata found in d:\codepython\anaconda3\envs\quant3810\lib\site-packages
Found existing installation: pyzmq 25.1.0
ERROR: Cannot uninstall pyzmq 25.1.0, RECORD file not found. You might be able to recover from this via: 'pip install --force-reinstall --no-deps pyzmq==25.1.0'.
(quant3810) PS C:\Users\cat> pip install --force-reinstall --no-deps --ignore-installed pyzmq==25.0.2
>>
Looking in indexes: https://mirrors.ustc.edu.cn/pypi/web/simple
Collecting pyzmq==25.0.2
  Using cached https://mirrors.tuna.tsinghua.edu.cn/pypi/web/packages/04/f1/feaf5d091173036ddbebbe0657453b122de167fd055e8d94a76aff862e99/pyzmq-25.0.2-cp38-cp38-win_amd64.whl (1.1 MB)
Installing collected packages: pyzmq
Successfully installed pyzmq-25.0.2
(quant3810) PS C:\Users\cat> pip uninstall -y pyzmq
Found existing installation: pyzmq 25.0.2
Uninstalling pyzmq-25.0.2:
  Successfully uninstalled pyzmq-25.0.2