Settings
Set environment variables in VS Code through terminal.integrated.env.linux
在 Visual Studio Code 中,您可以使用 terminal.integrated.env.linux
设置来为终端设置 Linux 环境变量。这些变量将在每次打开终端时自动设置,并对在终端中运行的任何命令都可用。
打开 Visual Studio Code 的设置(“File” -> “Preferences” -> “Settings”),然后在搜索框中输入 “terminal.integrated.env.linux”。在搜索结果中单击该设置,然后在右侧面板中编辑其值。
- 使用以下格式设置环境变量:
"terminal.integrated.env.linux": {
"VARNAME1": "value1",
"VARNAME2": "value2"
}
For instance, set env variables DISPLAY
and PYTHONPATH
shown as following.
"terminal.integrated.env.linux": {
"DISPLAY": "localhost:11.0",
"PYTHONUNBUFFERED": "1",
"PYTHONPATH": "${PYTHONPATH}:${workspaceFolder}/utils"
},
Reopen the terminal in VS Code through View -> Ternimal
, and check the values of env variables with the commond env
OR echo $DISPLAY
.
VS Code Remote-Containers:连接 docker 容器进行开发
https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers
- Open VS Code,
Ctrl + Shift +X
--> Search and InstallRemote-Containers
Extension.
(1) Attach to a running container
- Build a Docker container with
docker run -it <container-name>
- To attach to an already running Docker container for quick edits, debugging, and triaging.
selectRemote-Containers: Attach to Running Container...
from the Command Palette (F1
) .
(2) Download a file to local directory
scp [-r file ***]
Package python programs into executables
1 Prerequisites
1.1 Tools
- Install Pyinstaller with
pip install pyinstaller
- Install auto-py-to-exe with
pip install auto-py-to-exe
Pyinstaller
auto-py-to-exe is a .py to .exe converter using a simple graphical interface and PyInstaller in Python.
1.2 Documents and Videos for using the tool
Video for using auto-py-to-exe to package python program on Windows
Issues When Using auto-py-to-exe
Use Pyintaller command’s options
2 Package python programs into executables using auto-py-to-exe
- Launch the auto-py-to-exe with the commond
auto-py-to-exe
in the terminal, then a new tab will be created in your default internet Explorer. - Set three key options, including:
(1) Script Location: The script (contain themain
function) you call to run your project, so if your project is one script, put that here, if your project is more than one script, put the script that starts it here.
(2) onefile: Create a one-file bundled executable.
(3) Console Based: If you do want the console to appear, keep “Console Based is Selected”
(4) Additional files: Add extra files your project requires that aren’t Python files (e.g. images, csv, databases, …). When adding an entry, the file path/folder path needs to the in the box on the left and the destination on the right; the destination is the folder in the executable.
(5) --collect-all [MODULENAME]: Collect all submodules, data files, and binaries from the specified package or module.
(6) Click the big blue button at the bottom to package the project
(7) Open the location of the executable/package and run it
DEMO on Ubuntu: You can use the following command to package the project http://147.8.234.14:10101/lithium/battview
into an executable.
Script Location: select the script /home/pelops2/PycharmProjects/battverse/battview/src/battwin.py
–collect-data
[/home/pelops2/PycharmProjects/battverse/battview/src/assets] [assets]
–collect-all
add all module names, e.g., pyp4d, battopt
pyinstaller --noconfirm --onefile --console --clean --collect-all "pyp4d" --collect-all "battopt" --add-data "/home/pelops2/PycharmProjects/battverse/battview/src/assets:assets/" "/home/pelops2/PycharmProjects/battverse/battview/src/battwin.py"
DEMO on Win10:
–collect-data
[C:/Users/hkstp/Downloads/battview-main/assets] [assets/]
[C:/Users/hkstp/Downloads/battview-main/pyp4d] [pyp4d/] %Newly ADD
[C:/Users/hkstp/Downloads/battview-main/data] [data/] %Newly ADD
Copy the directory data
into the output to Run *.exe
3 Troubleshooting
-
Right-click context menu in vs code executes immediately
https://github.com/microsoft/vscode/issues/113175
Set your zoom level to default / 0. In settings.json add:window.zoomLevel
: 0 This works with all window styles, but obviously is not always viable
Change the title bar style from native to custom. In settings.json add:window.titleBarStyle
:custom
This will change how the title bar but also the context menus look. Setting this, you can zoom in again -
Open a file in a new tab by default
Do not select “Enable Preview Editors” by clicking … -
ERR: Fatal Python error: init_import_size: Failed to import the site module …
当PYTHONPATH设置错误(有多余的package路径)时,会出现该错误。 -
Use the relative file paths with respect to the current program execution path rather than to the current Python files, see the video
# quickstart_action = QAction(QIcon("./assets/qkstart.png"), "Quick Start", self)
icon_path = os.path.join(os.path.dirname(__file__), "assets/qkstart.png")
quickstart_action = QAction(QIcon(icon_path), "Quick Start", self)
[ERR] libGL error: MESA-LOADER: failed to open iris: /usr/lib/dri/iris_dri.so: cannot open shared object file: No such file or directory (search paths /usr/lib/x86_64-linux-gnu/dri:$${ORIGIN}/dri:/usr/lib/dri, suffix _dri)
[Solve]
rm /home/pelops2/miniconda3/lib/libstdc++*
OR conda install -c conda-forge libstdcxx-ng
Nuitka
PyOxidizer
AI Tools for programing
[1] GitHub Copilot is an AI-powered code completion tool that helps you write code faster and smarter.
GitHub Copilot
Install without root privileges
[JuNest] https://github.com/fsquillace/junest
[pget] https://github.com/0x00009b/pkget