Cannot Run Python From VisualStudioCode Terminal - python

So my pc was running as default a 32 bit python version, but I wanted to run the 64 bit that I had installed. But when I try to run python from my VSCode Terminal this is the result:
Javier Camacho#DESKTOP-9V7BRO5 MINGW64 /d/Javier Camacho Data/Escritorio/SS Progra/pruebas python
$ python
bash: /c/Users/Javier Camacho/AppData/Local/Microsoft/WindowsApps/python: Permission denied
and now I can't even run pip, because the same thing shows up:
Javier Camacho#DESKTOP-9V7BRO5 MINGW64 /d/Javier Camacho Data/Escritorio/SS Progra/pruebas python
$ pip -v
bash: /c/Users/Javier Camacho/AppData/Local/Microsoft/WindowsApps/pip: Permission denied
my computer runs windows 10. I have tried uninstalling all my python versions and installing them again but it hasn't worked.

set python path in your computer
Right click on My Computer ->Properties ->Advanced System setting ->Environment Variable ->New
In Variable name write path and in Variable value copy path up to C://Python(i.e., path where Python is installed). Click Ok ->Ok.

use sudo in prefix, Like..
sudo python
sudo pip -v

I found out that what git bash needed to find was the conda environment. You need to type conda init bash on the git bash console, close it, and then open it again. It should activate the conda base environment by itself and you can work from there.

Related

updated python3 now terminal wont start

On Ubuntu 18.04 LTS I have the standard Python 2.7 and Python 3.6. My default python pointed to Python 2. I then installed virtualenv:
$ sudo pip install virtualenv virtualenvwrapper
$ sudo rm -rf ~/get-pip.py ~/.cache/pip
And modified my .bashrc by adding these lines:
export WORKON_HOME=~/Envs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh
Everything was fine and I could make virtual environments, install packages, work in them, deactivate them, etc.
Then one day I decided to upgrade my Python 3 to Python 3.7 because I needed to use asyncio. I followed this guide.
I made the new Python 3 my default and all seemed fine until I tried to open a new terminal. I got a message about virtualenv not being installed and then got the command prompt. But it was dead - I could not type anything. I quit the terminal and now all I get is the word 'terminal' in the menubar with a little spinning circle for a little bit and then it disappears.
I commented out the lines in .bashrc about virtualenv but no joy.
EDIT:
Using xterm I did this
cd /usr/bin
sudo rm python3
sudo ln -s python3.6 python3
and rebooted.
Now I got my terminal back. python3 points to python 3.6.7. But I'm afraid of switching the symlink to 3.7.
UPDATE:
Even disabling virtualenv in .bashrc, rebooting, and trying to switch back to python3.7 reproduces the problem. I can invoke python3.7 directly from the command line and see the python3.7.1 prompt >>> but it seems the system does not like it to be the default python3.

Python and Conda not recognized in Ubuntu for Windows, although in PATH

I've installed Anaconda on my Windows machine, and made sure to add it to PATH.
Ubuntu for Windows will not recognize conda and python although they are in PATH
dean#DESKTOP-GJ4INGE:~$echo $PATH
...
/mnt/c/ProgramData/Anaconda3
/mnt/c/ProgramData/Anaconda3/Library/mingw-w64/bin
/mnt/c/ProgramData/Anaconda3/Library/usr/bin
/mnt/c/ProgramData/Anaconda3/Library/bin
/mnt/c/ProgramData/Anaconda3/Scripts
...
I've wanted to make sure They actually exists in PATH, so I opened Anaconda prompt
(base) C:\Windows\system32>where conda
C:\ProgramData\Anaconda3\Library\bin\conda.bat
C:\ProgramData\Anaconda3\Scripts\conda.exe
(base) C:\Windows\system32>where python
C:\ProgramData\Anaconda3\python.exe
Seems as if they are in the correct locations yet not recognized by Ubuntu.
Apparently Ubuntu is looking for the entire file name so the command conda.exe and python.exe work.
I think it would be a better and more useful idea to install python directly on WSL via sudo apt install python3 python3-pip and manually install the ubuntu package for conda.
If you want to preserve your current WSL configuration, the output from which python, which python and which conda and the complete echo $PATH would be needed to help you more. (All the commands in WSL)
From what you have submited I think your PATH is bad written because instead of newline the separator character between directories should be ':'.

issues with python virtual environment

I am facing following 2 issues:
python command is not using the virtualenvwrapper python.
After activating my virtual environment if I type python then the code still uses the native python libraries. I can easily install libraries etc with pip to my virtual environment but I cannot run any command using python.
e.g. if I execute $ ./manage.py runserverthen it is fine and I can run a django server
but if I try $ python manage.py runserver
or even just
$ python
then it uses the native python libraries and that should not happen
This is while using iterm or terminal in osx. I have never faced this problem in any linux based os
While using any os (linux based or osx), the workon command doesn't work inside any shell script, while it works normally in a terminal
os: osx
sounds like Python might be using the packages in site-packages, which means you should use the --no-site-packages flag when creating your virtualenv (although it seems like this is the default in the current version of virtualenv).
In order to access the virtualenvwrapper functions from a shell script, you will first need to source it: $ source /usr/local/bin/virtualenvwrapper.sh (the path might be different in your case).
You could try install virtualenv and virtualenvwrapper from pip3.
pip3 install virtualenv virtualenvwrapper
And then find where virtualenvwrapper.sh file is:
find / -name 'virualenvwrapper.sh'
I have mine in /usr/local/bin/virtualenvwrapper.sh. But it seems that you have it in some different directory. So you must change below config to fit your needs.
And then in your .bashrc or .zshrc:
# Python3 virtualenv/venvwrapper
export WORKON_HOME=~/.virtualenvs
VIRTUALENVWRAPPER_PYTHON='/usr/bin/python3' # This needs to be placed before the virtualenvwrapper command
export PROJECT_HOME=$HOME/Projects
source /usr/local/bin/virtualenvwrapper.sh # your path to virtualenvwrapper.sh
Let me know if it works :)

How do I make Python 3.5 my default version on MacOS?

I have just installed Python 3.5.1 on my Mac (running the latest version of OSX). My system came with Python 2.7 installed. When I type IDLE at the Terminal prompt my system pulls up the original Python 2.7 rather than the newly installed Python 3.5. How do I get my system to default to Python 3.5.1 when I open the IDLE window from Terminal?
Since Python 2 and 3 can happily coexist on the same system, you can easily switch between them by specifying in your commands when you want to use Python 3.
So for Idle, you need to type idle3 in the terminal in order to use it with Python 3 and idle for using it with Python 2.
Similarly, if you need to run a script or reach a python prompt from the terminal you should type python3 when you want to use Python 3 and python when you want to use Python 2.
It's good practice to have your MacOS Python environment set up properly from the beginning making sure that Homebrew installations take precedence over stock MacOS binaries. You want it in usr/local/bin not MacOS default usr/bin.
.bash_profile
# Ensure user-installed binaries take precedence
export PATH=/usr/local/bin:$PATH
# Load .bashrc if it exists
test -f ~/.bashrc && source ~/.bashrc
Can also create aliases for both.
alias py2='python2.7'
alias py3='python3.6'
Source the file to ensure it takes effect for the current session
source ~/.bash_profile
Homebrew install and setup etc...
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew doctor
brew update
brew upgrade --all
brew cleanup
Python3 install
brew install python3
Next
pip3 install virtualenv
Next
pip3 install virtualenvwrapper
When all is finished python3, pip3, virtualenv, and virtualenvwrapper.sh will all be in usr/local/bin.
Result
Every time I install anything or use commands like mkvirtualenv Python 3 is used by default.
You can use the python3 command (instead of using python), or you can simply uninstall the 2.7 version if you don't use it
If you dont have any python 2 scripts that you use, you can delete python2. But its not a problem to have them both installed. You just have to use another path python3 to launch IDLE.
I would prefer to let them both installled so if you have any scripts that are in python 2 you can still run them or you have to port them to python3.
You can switch to any python version in your project by creating a virtual environment.
virtualenv -p /usr/bin/python2.x (or python 3.x)
In case you just want to run a program in a specific version just open shell and enter python2.x or python3.x
Do right thing, do thing right!
Open your terminal,
input python -V, It likely shows:Python 2.7.10
input python3 -V, It likely shows:Python 3.7.2
input where python or which python, It likely shows:/usr/bin/python
input where python3 or which python3, It likely shows:
/usr/local/bin/python3
add the following line at the bottom of your PATH environment variable file in ~/.profile file or ~/.bash_profile under Bash or ~/.zshrc under zsh.
alias python='/usr/local/bin/python3'
OR
alias python=python3
input source ~/.bash_profile under Bash or source ~/.zshrc under zsh.
Quit the terminal.
Open your terminal, and input python -V, It likely shows:
Python 3.7.2
Note, the ~/.bash_profile under zsh is not that ~/.bash_profile.
The PATH environment variable under zsh instead ~/.profile (or ~/.bash_file) via ~/.zshrc.
Hope this helped you all!
By typing python, you are actually referring to a link.
You will find its location with $ which python. In my case it was /usr/local/bin/python. go there $open /usr/local/bin/ and just delete the original python, python-config and idle as they are
identical to the 2.7 files in the same folder.
Then duplicate the 3.5 files and rename them to what you just deleted.
This also changes the default link other editors like Sublime_ReplPython use and updates it therefore to the 3.5 Version. This was my major concern with the standard installation.

Pip3 packages can't be found/used by the terminal

I'm trying to use python3's built in pip3 package manager to install virtualenv and Django so I can learn more about python but after installing them both and trying to use virtualenv, the terminal throws:
zsh: command not found: virtualenv
But I can see that the virtualenv is installed on:
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages
I also tried creating a symlink to virtualenv.py to /usr/local/bin but when I try to run virtualenv in the terminal its giving me zsh: permission denied: virtualenv
I'm on a OS X machine. I installed Python 3 along side Python 2.7, which the machine came with.
Has anyone experience this problem before? I'd appreciate any advice/solution you guys could give. Thanks in advance!
You might use Bash before using Zsh. And the python had been updated when you used Zsh.
I got the same problem. Zsh could not find python3 packages. But when I changed the shell to Bash, the python3 packages could be found.
I solved the problem in the way as follows:
Open the terminal and input the command:
nano .bash_profile
Copy the settings in the .bash_profile:
# Setting PATH for Python 3.5
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH
Input the command:
nano .zshrc
Paste the code to the end of the .zshrc.
(.bash_profile is the settings file of Bash, .zshrc is the settings file of Zsh)
Restart the terminal.
Try to find the python3 packages, such as virtualenv:
which virtualenv
You may find the PATH of virtualenv.

Categories