SublimeREPL and IPython - python

I fail when I tried to use IPython with SublimeREPL.
My setup is:
- Windows 8.1
- Sublime Text 3
- C:\Python34
- C:\Python27
- C:\Anaconda3\Scripts -> Here it's where Ipython is
My PYTHONPATH and PATH are correct and I wrote in SublimeREPL settings - User:
{
"default_extend_env": {"PATH": "{PATH};C\\Anaconda3\\Scripts"}
}

It's solved. I make a file named Main.sublime-menu within the folder Sublime Text 3\Packages\User\SublimeREPL\config\Python
[
{
"id": "tools",
"children":
[{
"caption": "SublimeREPL",
"mnemonic": "r",
"id": "SublimeREPL",
"children":
[
{
"caption": "Python",
"id": "Python",
"children":[
{
"command": "repl_open",
"caption": "IPython - Anaconda",
"id": "repl_python_ipython",
"mnemonic": "p",
"args": {
"type": "subprocess",
"encoding": "utf8",
"autocomplete_server": true,
"cmd": ["C:/Anaconda3/Scripts/ipython", "--colors=NoColor"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python"
}
}
]
}
]
}]
}
]

SublimeREPL doesn't run ipython executable directly - it uses its API to start the console, therefore IPython needs to be importable, what means it needs to be on PYTHONPATH. So, extend default_extend_env config with PYTHONPATH pointing it to IPython source folder.

There are 2 ways to make it, win10, conda python3.6.7, Ipython7.1.1, Sublime 3.1.1
1.Open \Packages\SublimeREPL\config\Python\Main.sublime-menu, find the line
"windows": ["python", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"]
and change it to where your ipython.exe located, for me is
"windows": ["C:\\Python\\envs\\py37\\Scripts\\ipython.exe"]
2.Just modified \Packages\SublimeREPL\config\Python\ipy_repl.py to 3 lines,
import os
# change dir to path_to_ipython.exe
os.chdir(r'C:\Python\envs\py37\Scripts')
os.system('ipython')
I prefer the second one, if you encount problems with first way, such as your shortcut about sublimeREPL not work (happens to me:(), try second one.

Related

"Debug Adapter Executable not provide" in VS code for Python

Try to debug the Python code in Container using VS Code Remote Container Extension.
After the docker build task, I got a "Debug Adapter Executable not provide" error. Where could be wrong?
launch.json
{
"configurations": [
{
"name": "Docker: Python - General",
"type": "docker",
"request": "launch",
"preLaunchTask": "docker-run: debug",
"python": {
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/app"
}
],
"projectType": "general"
}
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "docker-build",
"label": "docker-build",
"platform": "python",
"dockerBuild": {
"tag": "py:latest",
"dockerfile": "${workspaceFolder}/Dockerfile",
"context": "${workspaceFolder}",
"pull": true
}
},
{
"type": "docker-run",
"label": "docker-run: debug",
"dependsOn": [
"docker-build"
],
"python": {
"file": "app.py"
}
}
]
}
Looks like it is resolved if you define a local python interpreter even if you want to use docker. Open a .py file and define it with the button right bottom.
I also encountered this problem. After trying a fresh install of the VS Code Docker extension, to no avail, I noticed the actually command being triggered by the "docker-run: debug" task in the tasks.json:
docker run -dt -P --name "loadtiktokcampaigns-dev" --label
"com.microsoft.created-by=visual-studio-code" -v
"/Users/tnightengale/.vscode/extensions/ms-python.python-
2022.12.0/pythonFiles/lib/python/debugpy:/debugpy:ro,z"
--entrypoint "python3" "loadtiktokcampaigns:latest"
The key here is the -v command that is attempting to mount the /debugpy files into the container from the VS Code Python extension files.
For some reason, those files were not actually located at that path on my Mac. Deleting the ms-python.python-2022.12.0/ folder and reinstalling the VS Code Python extension solved the issue for me.

Why vscode terminal show python version difference with interpreter?

as you see "python --version show python3.10.4
but the interpreter show python 3.7.3
how can i change the envirnment in vscode
If you click on the interpreter version being used by VSCode, you should be able to select different versions across your device.
Selecting the interpreter in VSCode:
https://code.visualstudio.com/docs/python/environments#_work-with-python-interpreters
To run streamlit in vscode:
Open the launch.json file of your project.
Copy the following:
{
"configurations": [
{
"name": "Python:Streamlit",
"type": "python",
"request": "launch",
"module": "streamlit",
"args": [
"run",
"${file}"
]
}
]
}
Adding the following line to your setting.json (crtl+shift+P "preferences: open settings(JSON)").
"terminal.integrated.env.osx": {
"PATH": ""
}

Visual Studio Code: Wrong separator being used after changing default terminal

In Visual Studio Code I changed the Default Terminal to Command Prompt.
When I want to debug my Azure Function the following command is executed:
Executing task: .venv\Scripts\activate ; func host start <
However, I think it should put the cmd separator "&&" instead of ";".
Otherwise the func host start will not execute.
Executing task: .venv\Scripts\activate && func host start <
As far as I know it should auto-detect this.
Is there a way to manually change this?
My settings.json:
{
"terminal.integrated.automationShell.windows": "C:\\windows\\System32\\cmd.exe",
"terminal.integrated.defaultProfile.windows": "Command Prompt",
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell"
},
"Command Prompt": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"args": [],
"icon": "terminal-cmd"
},
"Git Bash": {
"source": "Git Bash"
},
"C:\\windows\\System32\\cmd.exe": {
"path": "C:\\windows\\System32\\cmd.exe",
"args": [],
"icon": "terminal-cmd"
},
"JavaScript Debug Terminal": {
"extensionIdentifier": "ms-vscode.js-debug",
"icon": "debug",
"id": "extension.js-debug.debugTerminal",
"title": "JavaScript Debug Terminal"
}
}
}
Thanks in advance!
#########
SOLUTION:
I was able the change the separator by editing the tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "cmd host start",
"type": "shell",
"dependsOn": "pip install (functions)",
"windows": {
"command": "${config:azureFunctions.pythonVenv}\\Scripts\\activate && func host start"
},
"isBackground": true,
"problemMatcher": "$func-python-watch",
},
{
"label": "pip install (functions)",
"type": "shell",
"osx": {
"command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt"
},
"windows": {
"command": "${config:azureFunctions.pythonVenv}\\Scripts\\python -m pip install -r requirements.txt"
},
"linux": {
"command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt"
},
"problemMatcher": []
}
]
}
Afterwards in the launch.json, I set the preLaunchTask to "cmd host start".
Thank you ejizba. Posting your suggestion as an answer to help other community members.
"The debug configuration is specified in your tasks.json and launch.json files in the .vscode folder. The 'windows' 'command' properties default to a PowerShell separator (;), but you're welcome to switch it to a cmd separator (I believe that would just be &&) .
however, because I think we can potentially refactor the tasks.json so that it doesn't use terminal-specific separators and prevent similar issues in the future ."
For more information please refer this SO THREAD

vscode sphinx-build task in virtual environment [duplicate]

I have a python virtual environment declared in my workspace settings, everything is fine with it.
Now I have a build task that calls a make target which in turn calls a pip package. When I run it, it doesn't use my venv even though it is the selected interpreter.
I've tried to add a activate venv/... before calling my make command but I get a Permission denied error in the embedded terminal.
How can I use a virtual environment and tasks at the same time?
It might be a little late to answer your question but the trick is to set the command field to point to the virtual environment's python executable instead of the default python. If you set up your .vscode's settings.json correctly you should have something like this in your file:
{
"python.pythonPath": "env\\Scripts\\python.exe",
// other settings ...
}
Having this config in your workspace, you can then create a custom task of type process using ${config:python.pythonPath} as it's command field.
You can read all about it in this section of VSCode's docs.
This example creates a Django python manage.py migrate task:
{
"version": "2.0.0",
"tasks": [
{
"label": "Migrate",
"type": "process",
"command": "${config:python.pythonPath}",
"args": [
"${workspaceFolder}/src/manage.py",
"migrate"
],
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": true
},
"problemMatcher": []
}
]
}
I tested with the following tasks.json and it works:
{
"version": "2.0.0",
"tasks": [
{
"label": "test",
"type": "shell",
"command": "source /home/me/.pyenvs/myenv/bin/activate; make"
}
]
}
First activate virtual environment and then executes make.
I had quite a lot of trouble with this recently myself. I wanted to update package requirements before running code, but I didn't want to implement a complex or maintenance-heavy solution. The following works well for me across Windows, OSX, and Linux environments.
{
"version": "2.0.0",
"tasks": [
{
"label": "pipInstall",
"type": "shell",
"command": "${command:python.interpreterPath}",
"args": ["-m", "pip", "install", "-r", "requirements.txt"]
}
]
}
I believe ${command:python.interpreterPath} points to whatever interpreter path one selects while setting up the environment.
You can modify the shell in tasks.json in a way that works for bash and cmd shells. This worked for me and it correctly prints the full path to the python executable in the virutal environment.
{
"version": "2.0.0",
"linux": {
"options": {
"shell": {
"executable": "bash",
"args": [
"--init-file",
"env/bin/activate",
"-ci",
]
}
},
},
"windows": {
"options": {
"shell": {
"executable": "cmd.exe",
"args": [
"/C",
"env\\Scripts\\activate.bat",
"&"
]
}
}
},
"tasks": [
{
"label": "test shell with virtualenv",
"command": "which python", // where on Windows for testing
"type": "shell",
"group": "build",
"problemMatcher": []
}
]
}
I'm late to the party, but this alternative might be useful. If you use pipenv in stead of standard venv, you can use pipenv run. It will activate the virtualenv before running the process. For example, this works for building sphinx:
{
"version": "2.0.0",
"tasks": [
{
"label": "build html",
"type": "process",
"command": "pipenv",
"args": [
"run",
"sphinx-build",
"-b",
"html",
"${workspaceFolder}",
"${workspaceFolder}/_build/html"
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "always",
"panel": "new"
}
}
]
}
For people who maybe using Poetry a solution is to run
poetry shell
before running VSCode but a better solution is to do the following. This has been mentioned in an earlier answer but not specifically for poetry.
Use Poetry for Python Dependency

Setting python path for sublimerepl from sublime text?

I use python portable along with sublime portable of a memory stick and decided to install sublime REPL however when trying to use python portable as the build path for sublimerepl it does not specify it.
To put it simply I can't specify the sublimerepl python path like I can with straight sublime text!
I have tried adding the following into SublimeREPL.sublime-settings
"default_extend_env": {"PATH": "{PATH}:C:\\Users\\Andy\\Documents\\_Main\\M-Stick Backups\\08.07.13\\Computing\\Python Portable\\Portable Python 2.7.3.1\\App\\python.exe"},
I have also tried changing:
"cmd": ["python", "-i", "-u"],
to
"cmd": ["C:\\Users\\Andy\\Documents\\_Main\\M-Stick Backups\\08.07.13\\Computing\\Python Portable\\Portable Python 2.7.3.1\\App\\python.exe", "-u", "$file"],
within Python/Main.sublime-menu
Note in normal sublime I add the following to Python.sublime-build:
{"cmd": ["C:\\Users\\Andy\\Documents\\_Main\\M-Stick Backups\\08.07.13\\Computing\\Python Portable\\Portable Python 2.7.3.1\\App\\python.exe", "-u", "$file"],"file_regex": "^[ ]*Iile \"(...*?)\", line ([0-9]*)","selector": "source.python"}
Any ideas?
Thanks,
Andrew
Is it possible you're changing the wrong line of code in /Packages/SublimeREPL/config/Python/Main.sublime-menu? If you wish to run REPL on the current file,
{"command": "repl_open",
"caption": "Python - RUN current file",
"id": "repl_python_run",
"mnemonic": "d",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["C:\\Users\\Andy\\Documents\\_Main\\M-Stick Backups\\08.07.13\\Computing\\Python Portable\\Portable Python 2.7.3.1\\App\\python.exe", "-u", "$file_basename"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
is what the modified section should look like. (It appears you might be modifying the command which opens the interpreter in interactive mode as opposed to running the current file).
Thanks to Hower... I installed the package control, then the sublimePREPL package and, then in the keybinding (under preferences) I wrote this int the user file:
[
{"keys": ["ctrl+b"], "command": "repl_open",
"caption": "Python - RUN current file",
"id": "repl_python_run",
"mnemonic": "d",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["C:\\Users\\giova\\AppData\\Local\\Programs\\Python\\Python37-32\\python.exe", "-u", "$file_basename"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}}
]

Categories

Resources