来自官方 winshell 网站的示例 https://winshell.readthedocs.io/en/latest/cookbook/shortcuts.html#create-a-shortcut-to-a-file
import os, sys
import winshell
shortcut = winshell.shortcut(sys.executable)
shortcut.working_directory = "c:/temp"
shortcut.write(os.path.join(winshell.desktop(), "python.lnk"))
shortcut.dump()
安装库时(https://winshell.readthedocs.io/en/latest/index.html)
pip install winshell
给出以下消息
PS C:\Users\bro> pip install winshell
Requirement already satisfied: winshell in c:\python\python312\lib\site-packages (0.6)
运行脚本时,会出现错误
"C:\Python\proekt\09 - Создание прфиля chrome\pythonProject\.venv\Scripts\python.exe" "C:\Python\proekt\09 - Создание прфиля chrome\pythonProject\main.py"
Traceback (most recent call last):
File "C:\Python\proekt\09 - Создание профиля chrome\pythonProject\main.py", line 3, in <module>
import winshell
ModuleNotFoundError: No module named 'winshell'
那么如何安装winshell库并使用它呢?
如果有人有类似的错误,我发现了问题。当然,你在提问时需要指定你在什么环境下运行python脚本。而且我是在pycharm中启动的,所以,创建项目的时候,pysherm写的是使用系统中安装的解释器,查看项目参数发现解释器是安装在本地的,即只是为了这个系统中未安装所有库的项目,必须为特定项目重新注册它们
您需要选择系统解释器,或为项目安装库。
错误是我在编写脚本时想使用系统解释器,以便在没有编程环境的情况下运行它