richardmyu / blog

个人(issues)博客
https://github.com/richardmyu/blog/issues
MIT License
0 stars 0 forks source link

python 相关问题记录 #31

Open richardmyu opened 2 years ago

richardmyu commented 2 years ago

1.venv 虚拟环境

今天尝试 venv 虚拟环境:

python -m venv envdemo
cd envdemo/Scripts
activate

我的默认终端是 powershell,在这一步激活报错:

activate: The term 'activate' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Suggestion [3,General]: The command activate was not found, but does exist in the current location. PowerShell does not load commands from the current location by default. If you trust this command, instead type: ".\activate". See "get-help about_Command_Precedence" for more details.

Suggestion [4,General]: The most similar commands are: Get-Date, Set-Date, compare, write, cat, at.exe.

而切换成 cmd,则激活正常。

根据 venv --- 创建虚拟环境 提示:

注解: 在 Microsoft Windows 上,为了启用 Activate.ps1 脚本,可能需要修改用户的执行策略。可以运行以下 PowerShell 命令来执行此操作: PS C:> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser 参阅 About Execution Policies 以获取更多信息。

但我的电脑,设置过后,还是无法启动该:

Activate.ps1: The term 'Activate.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Suggestion [3,General]: The command Activate.ps1 was not found, but does exist in the current location. PowerShell does not load commands from the current location by default. If you trust this command, instead type: ".\Activate.ps1". See "get-help about_Command_Precedence" for more details.

Suggestion [4,General]: The most similar commands are: RMActivate.exe.
richardmyu commented 2 years ago

2.pycharm 中文切换 bug

Ubuntu v20.04 pycharm v.2021.2.3

有一定概率,当输入一两个中文后,再输入中文,会被强制输入成字母,不论是否主动切换输入法,始终表现为英文输入。

解决方法:

  1. 点击 pycharm 菜单:Help -> Edit Custom VM options...
  2. 末尾添加 -Drecreate.x11.input.method=true
  3. 重启 pycharm;

参考:

1.ubuntu20.4 pycharm 无法输入中文(抓狂)

richardmyu commented 6 months ago

3.批量删除包

1.使用 requirements.txt 文件为中介,写入需要删除的包,再批量删除

pip freeze > requirements.txt
pip uninstall -r requirements.txt -y

2.如遇权限问题,以管理员身份打开 cmd 运行上述命令。