Arrow up / previous command in VSCode Python Interactive not working - python

I'm working with VSCode on an Ubuntu 18.04 machine. Everything is fine except that I can't get back to the previous command in Python Interactive Window via Arrow Up. It works in the integrated terminal though, integrated shell is /bin/bash.
I have no idea where this is coming from. I changed "keyboard.dispatch" to "keyCode", but that's not the problem. I also tried different versions of the python-extension.
Do you have any idea?
Thanks!

Not sure if this is helpful for you as an Ubuntu user, but I came across the same problem in Windows this week. In my case, the issue cropped up after I installed the Python extension in VS Code (or at least I didn't notice the issue before this). The combination of using the Python extension, Git Bash for terminal, and python virtual environment killed the up arrow feature for me. Using python outside a virtual environment works fine. My solution was to use Command Prompt as the terminal when I wanted to use a virtual environment interactively.

In my situation, although I delete all the shortcuts of UpArrow, I still can get the previous command through UpArrow in Python interactive. This means there's no way to configure this shortcut, it was built in the plugin which built in Python extension.
So it's some problem with your Python extension, but you said you have tried to install a different version of Python extension but still not work. Make sure you have deleted it completely -> delete the extension folder manually(it's under C:\Users[UserName].vscode\extensions\ms-python.python-xxx).

Related

vsCode won't recognize python installation, but does?

When I put "py --list" in the terminal I get this:
Installed Pythons found by C:\Windows\py.exe Launcher for Windows
No Installed Pythons Found!
I set my environment variables. I actually got VS Code to run some code I threw together that didn't use any imports, but now that I'm trying to use any python commands in the terminal, I'm getting errors. What gives?
python should work, since it is finding installations.
If you are working on Windows, very often it's all about permissions. Try running your terminal and VSCode as administrator! Worked a lot of times for me, also with other languages.
Please ensure that you have installed the python extension and selected the correct python interpreter (Ctrl+Shift+P and type Python: Select Interpreter).
If this didn't work, you may have to reinstall python.
Read the document about Vscode-Python for more details.

Unable to change Python 2.7 to Python 3.8 on Sublime and VS code

I have been trying to change my python interpreter on sublime text and VS code and no matter what I do, both of them refuse to change. It always picks the default Python 2.7 version.
On sublime, I tried to create a new build tool, added the path to Python3 but nothing is working.
And on, VS code, even if I select Python3 from the drop-down menu, it doesn't change anything.
I changed the system's default python interpreter from 2.7 to 3.9 and set the path on bash profile. It fixed the issue for me.
I don't know about Sublime, but for VS Code, there looks to be quite a few things to verify:
Check your User Settings on whether you've set up a default interpreter for your applications
Are you using Window 10 WSL? Then you might want to check out issue 3227 for vscode-remote-release where the comment was:
So I was having this same exact issue until I read this article on a wsl tutorial. In there it says we should have "Remote - WSL" extension installed (already did). In the bottom left corner "Remote - WSL" installs a status button that has the "greater than" and "less than" symbols displayed. If you click that button and tell VSCode to open up in the remote WSL distro environment it fixed my issue where vscode was unable to find an interpreter for python.
For Sublime, you need to hit ⌘B with your script pane focused in order to use your new python3.sublime-build build system.
It looks like you are running your script within Terminus, which is fine, but you need to use the python3 command when running it from the command line, even if that command line is within Sublime.
Please check out my answer here on how to make a Python build system that accepts user input, as the Sublime "console" doesn't allow you to interact with your program. Since you already have Terminus installed, I'd recommend going down to the bottom of the answer and using the Terminus build system. That way, you won't have to deal with Terminal windows opening every time you run a build.
The terminal window uses your PATH, not the IDE settings, so manually typing out python --version isn't testing anything except the PATH variable
In order for the terminal to use the "correct" python binary you've specified, it would need to give the absolute path to it, which I believe using Command+B (using the build options) in Sublime would do. Similarly, you can use the Run/Debug Configurations in VSCode.
Or you can modify your ~/.zshrc to fix your PATH, for example installing pyenv to change the entire system Python version, or the one for the current folder

How to tell VScode, on my Mac running high Sierra, which version of python to use

I use VScode to write and run python. I use it with a Jupyter extension. I have 2 virtual environments created using Anaconda. One py27, for python 2.7.13 and the other, py36, for Python 3.6.5.
I have a simple code which I edited to only run in python2. When I run VScode, the virtual environment I run it in does not seem to matter. VScode seems to run but I can't figure out how to make it use py36 (python 3.6.5) or py27 (python 2.7.13).
By using different commands in the command palette, or double-clicking on phrases in the bottom border of VScode I can eventually get it to run which version I want. But I have not found a reproducible method.
I have tried about 100 times with no luck. I thought I found a method that would repeat but I tried it again and it didn't work.
I know this question is very vague but it would take pages to explain what I've tried. I have about 5 or 6 settings which I've tried a plethora of combinations. One of the commands I tried is to select a python interpreter. I have several options but none seem to have an effect. Also, in the bottom border of the VScode window, there is the name of a specific python interpreter. You can click on this to select a different python interpreter. As far as I can tell this doesn't do anything. Actually, it's a hindrance because a user may think they are actually using that interpreter.
I've tried both py27 and p36 but I get no difference. If I can get visual studio code to start out in py27, I can make it change to py36 and back to py27. But how to make it start in py27 seems random. My virtual environments are in my home directory, /User/myname/py27 for example along with the VScode app.
The documentation at https://code.visualstudio.com/docs/python/environments explains how to select your virtual environment. Without knowing where you installed the virtual environments the best I can tell you is you can manually specify what interpreter to use with the python.pythonPath setting or if you have both virtual environments in a directory outside of your workspace folder you can specify the common folder with the python.venvPath setting.

Adding Python 2.7 & 3.x Interpreters to PyCharm

I'm having issues adding a project interpreter to PyCharm from a new Anaconda environment. I have Anaconda2 installed with one Python 2.7 environment (C:\Anaconda2\python.exe) that I've been using on Pycharm without issue for several months.
I am attempting to add a second Python 3.6 interpreter (from C:\Anaconda2\envs\py36\python.exe) to my PyCharm. After adding the Local Interpreter to Pycharm, I run into a MS Visual C++ Runtime Error R6034 "An application has made an attempt to load the C runtime library incorrectly".
From cursory googling, it seems that there could be a runtime DLL conflict (potentially msvcr90.dll) between Python 2 & 3. All fixes I see involve editing the executable path of the application, but I don't think this is feasible for my Pycharm use case. How do I get rid of this error, or just generally be able to use both Python 2 & 3 interpreters through my PyCharm?
I think that's the problem with Anaconda and different msvc dll in the computer.
You can test the conda command in the command line, to see if R6034 happens. If it happens, try the following solution:
I had a similar problem with Anaconda3 and Python27. I solved this problem via executing the following command in cmd, outside of any conda environment:
conda install msvc_runtime
After installing the packages, open a new command and test if the R6034 error still appears.
I had a similar issue and was able to resolve it by selecting:
File --> Invalid Caches / Restart...
from PyCharm's main menu.
You may also want to double check that any Conda Environments that you have defined as Python Interpreters in PyCharm are properly configured per the docs
This issue was absolutely maddening. Million R6034 error windows would just keep popping up one after another if I just wanted to get help on a function. I researched it for months, on/off, opened tickets with JetBrains to no avail.
If you need to have multiple versions of Anaconda, and if you have Anaconda paths in your PATH, before launching PyCharm, delete all Anaconda paths from PATH, and then start PyCharm. You need to create a separate wrapper launcher script for PyCharm to fix PATH before PyCharm is started. Note that alternative of starting PyCharm and then fixing interpreter and python console PATHS inside PyCharm do not really work. Because PyCharm may be using a system path to access python to read documentation etc. So the only clean fix is to fix the system PATH before PyCharm starts.
Once you understand what needs to be done, then you can use your own steps/tools. This worked for me:
Create a script that modifies PATH. I used Python for that, sed or any other tools are fine too. The script simply examines each path element and removes it if it refers to Anaconda, and then puts it back together:
path_cleanup.py:
path_old = os.environ['PATH']
path_python_removed = [loc for loc in path_old.split(pathsep) if not ('python' in loc or 'Ana' in loc)]
print(pathsep.join(path_python_removed))
Create Powershell script to fix PATH and start PyCharm from that clean environment. To find PyCharm path, the simplest is to start it up the usual way, and head to Task Manager, right mouse click on pycharm64.exe process and select "open file location" to get the full path.
pycharm_clean.ps1
$Env:Path=python path_cleanup.py # call the script to fix the PATH
start-process $PYCHARM_PATH\pcharm64.exe -WindowStyle Hidden # enter your full path to pycharm and put it into background.
You can create a shortcut to launch pycharm_clean.ps1 + you can add it to your windows start up folder to be launched upon login: %APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup\
If you use BASH inside Cygwin, then steps for path clean up require a bit more tuning, but nothing you cannot do. If you need help, put a comment and I can add that script as well.

Python console not launching properly from command line

I seem to have problem launching python from command line. I tried various things with no success.
Problem: When trying to run python from the command line, there is no response i.e. I do not get message about 'command not found' and console does not launch. Only option to open python console is to run C:\Python34\python.exe directly. Running using python command does not work even when in the python directory but python.exe launches. Issue with the launching this way is that python console is launched in new window. This whole problem is present only on one machine while on my other machine I am able to run python correctly and console launches in the command prompt window from which the python command was executed.
PATH is correctly set to
C:\Python34\;C:\Python34\Scripts;...
and where python correctly returns C:\Python34\python.exe. I verified that running other commands imported through PATH (such as javac) run correctly.
Things I tried:
Completely re-installing python both with x86 and x64 python installations with no success.
Copy installation from my second machine and manually set the path variables - again no success.
Can anyone hint how to resolve this behavior?
(Additional info: Win 8.1 x64, python 3.4.2)
Issue resolved. Since no feasible solution was found in 2 days, I decided to wipe all keys containing 'python' from registry as well as some files that were not parts of other programs. This resolved the issue after re-installing python.
If anyone finds the true cause of this misbehavior and other - less brutal - solution, please write it here for future reference.
Recent Python installer has option to add PATH.
If you didn't use it, you can register directory where python.exe is to PATH environment variable.
But I prefer py launcher. It may be installed via Python 3.3 or 3.4.
With it, you can start Python via py or py -3.4.
See https://docs.python.org/3/using/windows.html#python-launcher-for-windows

Categories

Resources