$ where python
C:\Users\Idan\AppData\Local\Programs\Python\Python38\python.exe
C:\Users\Idan\AppData\Local\Microsoft\WindowsApps\python.exe
The Error:
Idan#DESKTOP-A16D3QA MINGW64 ~/Desktop/ttt
$ C:\Users\Idan\AppData\Local\Programs\Python\Python38\python.exe -u "c:\Users\Idan\AppData\Local\Programs\Python\Python38\s.py"
bash: C:UsersIdanAppDataLocalProgramsPythonPython38python.exe: command not found
deafault settings json file:
// Path to the pipenv executable to use for activation.
"python.pipenvPath": "pipenv",
// Path to the poetry executable.
"python.poetryPath": "poetry",
// Path to Python, you can use a custom version of Python by modifying this setting to include the full path.
"python.pythonPath": "python",
settings.json
What I tried to do (integrate pipenv instead of venv):
"python.pythonPath": "C:\\Users\\Idan\\AppData\\Local\\Programs\\Python\\Python38\\python.exe",
"python.pipenvPath": "pipenv",
"python.testing.pytestEnabled": true,
"python.venvPath": "C:\\Users\\Idan\\.virtualenvs",
],
"code-runner.executorMap": {
"python": "$pythonPath -u $fullFileName"
},
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
other configuration I tried resulting in same error:
"python.venvPath": "C:\\Users\\Idan\\.virtualenvs",
// this is the actual locatation
// of the pythonpath C:\\Users\\Idan\\.virtualenvs\\Idan-iyfIpKqV\Scripts\python.exe
"python.pythonPath": "$venvPath\\pipenvPath\\Scripts\\python.exe",
//"python.pythonPath": "$venvPath\\ENV-NAME\\Scripts\\python.exe",
This is the full settings.json I have:
https://gist.github.com/IdanBanani/0d562770f14f3098debb6e1d47179e3f
previously, combining lines from these two sources was working (venv):
https://github.com/CoreyMSchafer/dotfiles/blob/master/settings/VSCode-Settings.json
https://github.com/xames3/xai_django/blob/bcaf169837d484d0bcf8686c18dc0529d1469034/.vscode/settings.json
but I tried to replace to pipenv, and might try in the future to automatically set it to create and activate the virtualenv
(pipenv install, pipenv shell) but not sure how easy it is
Also: I had to remove these lines of the thefuck project from .bashrc file because of error messages in the output console(maybe the installation/pip package got removed)
eval $(thefuck --alias)
# You can use whatever you want as an alias, like for Mondays:
eval $(thefuck --alias FUCK)
This is my current fix, but I don't think it's good enough for the generic case
Why does it keep creating the virtual env in a constant folder name Idan-iyfIpKqV?
"python.venvPath": "C:/Users/Idan/.virtualenvs",
"python.pythonPath": "C:/Users/Idan/.virtualenvs/Idan-iyfIpKqV/Scripts/python.exe",
Related
Okay, I've looked through a bunch of python venv with sublime text questions, and I'm pretty sure this issue is due to the specifics of venv on windows.
I'm on Windows, using Python 3.10, and the virtualenv package to manage my virtual environments.
I'm trying to set up a custom build in a Sublime project file that does the following:
activate the venv for the local project
echos the VIRTUAL_ENV to the shell to show the correct venv has been activated
I've been having issues with getting both into one build command, so here's the current array with the two steps as seperate builds:
"build_systems":
[
{
"name": "activate",
"cmd": "$project_path/venv/Scripts/activate.bat",
"shell": true
},
{
"name": "Current VENV?",
"cmd": "echo %VIRTUAL_ENV%",
"shell": true
},
]
Currently, when I run the activate build, I get the following:
The system cannot find the path specified.
[Finished in 80ms with exit code 1]
[cmd: C:\Users\kreeh\Repos\project/venv/Scripts/activate.bat]
[dir: C:\Users\kreeh\Repos\project]
If I run C:\Users\kreeh\Repos\project/venv/Scripts/activate.bat in a separate cmd.exe window, it correctly activates the venv, and when I print the %VIRTUAL_ENV% var, it correctly returns the venv location.
C:\Users\kreeh>C:\Users\kreeh\Repos\project/venv/Scripts/activate.bat
(venv) C:\Users\kreeh>echo %VIRTUAL_ENV%
C:\Users\kreeh\Repos\project\venv
I assume this is an issue with how the Sublime Text build system is handling the windows path formatting. If I try and utilize the working directory param, it doesn't work, because the cmd.exe doesn't do relative paths nicely.
{
"name": "activate",
"cmd": "venv/Scripts/activate.bat",
"working_dir": "${project_path}",
"shell": true
},
returns
'venv' is not recognized as an internal or external command,
operable program or batch file.
[Finished in 60ms]
So, is there a way to have the Sublime Build system handle the windows path correctly, or is there a way to use a relative path in the cmd?
#MattDMo pointed out the flaw in my logic, which is that the venv activation doesn't actually do anything in and of itself -- it changes the python interpreter used for future commands in that prompt window. As such, it's kind of a useless thing for a build system. Instead, I added a venv-specific pip install and build commands so far.
{
"build_systems":
[
{
"name": "pip install",
"cmd": "${project_path}/venv/Scripts/pip3.exe install -r requirements.txt ",
"working_dir": "${project_path}",
"shell": true
},
{
"name": "VENV Build",
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"cmd": "${project_path}/venv/Scripts/python.exe $file",
"shell": true,
},
],
"folders":
[
{
"follow_symlinks": true,
"path": "."
}
],
One thing to note, as a Windows user, I had to add the follow_symlinks=true to the folders list -- this is because the way venv works on windows (or at least on MY install), there's not an actual python.exe in that venv folder, it's a symlink.
I set my settings.json to Anaconda python 3.6.10 but Code runner still runs the code in 3.7.6. I used OS to check and in fact, that is true. I then used terminal to run my file and it is Python 3.6.10. How can I change my Code Runner to run at whatever version I set in the .vscode settings.json file?
"code-runner.executorMap": {
"python": "$pythonPath -u $fullFileName",
},
With this it should follow the anaconda settings in VS Code.
I've installed most popular Python extensions in vscode. So I can do shift+enter to execute some selected code into a python terminal.
This uses /usr/bin/python3 as default. I would like to use IPython3 instead. However, I don't find such settings in settings.json.
How can I configure the default Python terminal in vscode?
1.The reason for "I can do shift+enter to execute some selected code into a python terminal." is that "shift+enter" is the default shortcut key of VSCode, and the command it executes is "python.execSelectionInTerminal":
{ "key": "shift+enter", "command": "python.execSelectionInTerminal",
"when": "editorTextFocus && !findInputFocussed && !jupyter.ownsSelection && !replaceInputFocussed && editorLangId == 'python'" },
2.Set the default terminal to ipython in VSCode, please use "ipython.exe" to execute the file in settings.json: for example:
"terminal.integrated.shell.windows": "D:\\Users\\...\\AppData\\Local\\Programs\\Python\\Python38\\Scripts\\ipython.exe",
Use:
Open a file with the suffix .ipynb and vs code will do the rest
On Windows 10, I'm running VS Code 1.48.2 and Python 3, both installed on a thumb drive. I added an F:\Programs\VS Code\data folder with user-data andextensions. My project directory is F:\MyProject and it has a Pipfile. My project directory has a .env file and .venv\ so that pipenv will install to the local .venv\. What else do I need to get this environment working? Thanks!
.env file:
PYTHONPATH="F:\\Python\\Python38\\python.exe"
PYTHONHOME="F:\\MyProject\\.venv\\Scripts"
PIPENV_VENV_IN_PROJECT=True
F:\MyProject\.vscode\settings.json file:
{
"python.pythonPath": "f:\\MyProject\\.venv\\Scripts\\python.exe"
}
Although, when I used Preferences: Open Settings, it opened my F:\Programs\VS Code\data\user-data\settings.json file, though the paths look right (to me):
{
"editor.suggestSelection": "first",
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
"python.languageServer": "Microsoft",
"python.pythonPath": "${workspacefolder}/.venv/Scripts/python.exe",
"python.venvPath": "${workspacefolder}/.venv",
"python.venvFolders": [
".venv",
"${workspacefolder}/.venv"
]
}
Used the following steps to setup:
ps > cd F:\MyProject
ps > F:\Programs\VS Code\code.exe .
[In vscode integrated terminal]
PS F:\MyProject> py -m venv --system-site-packages .venv
PS F:\MyProject> pipenv shell
Loading .env environment variables…
Warning: Your Pipfile requires python_version 3.8, but you are using unknown (F:\M\.venv\S\python.exe).
$ pipenv --rm and rebuilding the virtual environment may resolve the issue.
$ pipenv check will surely fail.
Launching subshell in virtual environment…
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6
PS F:\MyProject> ls .\.venv\Scripts\python.exe
Directory: F:\MyProject\.venv\Scripts
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 9/6/20 3:04 PM 532040 python.exe
PS F:\MyProject> python where
Python path configuration:
PYTHONHOME = 'F:\MyProject\.venv\Scripts'
PYTHONPATH = 'F:\Python\Python38\python.exe'
program name = 'F:\Python\Python38\python.exe'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = 'F:\\Python\\Python38\\python.exe'
sys.base_prefix = 'F:\\MyProject\\.venv\\Scripts'
sys.base_exec_prefix = 'F:\\MyProject\\.venv\\Scripts'
sys.executable = 'F:\\MyProject\\.venv\\Scripts\\python.exe'
sys.prefix = 'F:\\MyProject\\.venv\\Scripts'
sys.exec_prefix = 'F:\\MyProject\\.venv\\Scripts'
sys.path = [
'F:\\Python\\Python38\\python.exe',
'F:\\Python\\Python38\\python38.zip',
'F:\\MyProject\\.venv\\Scripts\\DLLs',
'F:\\MyProject\\.venv\\Scripts\\lib',
'F:\\Python\\Python38',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
Current thread 0x000020d4 (most recent call first):
<no Python frame>
PS F:\MyProject>
According to your description, you could refer to the following steps to use the virtual environment:
Open this project in VSCode.
According to the information you provided, there is already a virtual environment ".venv" in your project, so there will be a ".venv" folder after opening. like this:
Click "select Python Interpreter" in the lower left corner to select the ".venv" virtual environment:
VSCode has selected the virtual environment, and then we open a new terminal console through the shortcut key "Ctrl+Shift+`", VSCode will automatically enter the current virtual environment:
Use pip to install the module "PySimpleGui": (pip install PySimpleGui)
When we run the python script, VSCode showed that the module PySimpleGui could not be found. We found "Lib\site-packages" in the ".venv" folder of the project and changed "PySimpleGUI" to "PySimpleGui":
The python script runs successfully in the virtual environment:
I'm trying to install & start npm in my mac terminal and I got this error.
I'm not sure what's the problem, I downloaded npm, python3, pip, but it still complaining.
Does any expert have an answer to this?
1) go project directory
2) open package.json
3) you can see scripts key, change the script key like this "start":"which command you want to execute"
Example
"scripts": {
"start": "node index.js" or "nodemon index.js" // which file you wants to run
}
if package.json not found in your project directory means, run npm init inside your project directory