I just installed python 3.6.2.
I then opened the mac terminal and typed:
python3 -V
and it said: "command not found"
I then changed the directory to the desktop and repeated the same command and it gave the same result. Then i tried:
type -a python
and it said: python: not found
You should firstly add the python executable path to the environment variable $PATH, then you'll be able to run the command wherever you are.
In your terminal:
touch ~/.bash_profile; open ~/.bash_profile
export PATH="path-to-your-python-folder:$PATH"
save it and exit (Command + Q)
force execute it with: source ~/.bash_profile
Reboot your system, then you should be able to run it.
Related
I am installing Python 3.7.2 for the first time, and I'm using the VS Code python extension.
When I run python -V I get Python 2.7.10 which is not correct!
When I select the usr/local/bin/python3 interpreter in VS Code I get this error when running a script:
bash: /Users/erik/Work/Python/usr/local/bin/python3: No such file or directory
But when I look in usr/local/bin I can see that Python3 is there. I'm not sure why VS Code pastes the work directory in front of usr/local/bin ?
My first thought was that Python3 should be in the PATH variable so I ran the included Update Shell Profile command, which gives this feedback:
This script will update your shell profile when
the 'bin' directory of python is not early enough
of the PATH of your shell.
All right, you're a python lover already
Now, after rebooting VS Code I get a new option for selecting an interpreter:
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
Is that different from the Python in usr/local/bin ? When I select it, I get this error:
The script isort is installed in '/Users/erik/Library/Python/3.7/bin' which is not on PATH.
I also get this sideways related error:
You are using pip version 18.1. You should consider upgrading via the 'pip install --upgrade pip' command.
But, when following these instructions I get yet another error:
bash: pip: command not found
All in all, this process and the official documentation seem less than user-friendly? Apparently I'm required to dig deep through my mac's system files in the terminal before even writing one line of code.
Am I missing an essential step here?
I suggest that you use virtual environment for your project
first
pip install virtualenv
open cmd in your project directory that you open in VS-Code (it's important that vs-code sees this virtualenv folder that we will create)
mkvirtualenv my_env
and it will activate it automatically. if not run
my_env/bin/Scripts/activate or my_env/Scripts/activate
Then go open vs-code then select my_env for python interpreter
Well, if you want to change your default Python version for the whole system, it might break some applications that are depending on Python 2.
You can alias the commands by adding this line to your ~/.bash_profile:
$ alias python='python3'
The python command will now refer to python3.
If you want to execute the original Python (which refers to python2), you can escape the alias (so \python will launch python2 without touching the alias).
Btw.
$ unlink /usr/local/bin/python
$ ln -s /usr/local/bin/python3.7 /usr/local/bin/python
could also be a workaround for you.
I'm using Windows 10 and recently installed Windows Subsystem for Linux.
Anaconda was already installed on my PC at that point.
When I try to run conda commands on Bash on Ubuntu on Windows I get the following error:
$ conda conda: command not found
Other related answers, such as this or this suggest adding
C:\Users\«user»\Anaconda3\Scripts
C:\Users\«user»\Anaconda3
to $PATH. But as you can see below, both are already included (I didn't add them manually):
$ echo $PATH | tr ':' '\n'
...
/mnt/c/Users/«user»/Anaconda3
/mnt/c/Users/«user»/Anaconda3/Scripts
/mnt/c/Users/«user»/Anaconda3/Library/bin
...
The following conda files are available in Anaconda3/Scripts:
conda.exe
conda-env.exe
conda-env-script.py
conda-script.py
conda-server.exe
conda-server-script.py
The commands work just fine in both PowerShell and cmd.
What am I missing?
[EDIT]: Corrected second URL and changed user to < user > in Anaconda3 paths above.
Try to run conda.exe instead of conda.
Windows assume .exe marks a file as executable, and ignores that extension when looking for the binary. Linux uses a flag, so any file can be an executable, and you need to provide the full name because there is no assumption on the extension.
Run conda init
.anaconda3/bin/conda init
.miniconda/bin/conda init
To add conda to Windows Subsystem Linux, this is the correct way:
curl https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -o Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
export PATH=$PATH:/miniconda3/bin
You will need to restart WSL for the env path to work.
I just entered a class as an introduction to Python, and so I downloaded GitBash and Andaconda on my Windows laptop. I navigated to my python file on GitBash and tried to execute my python file, to no avail. I searched this website for answers on what to do and tried as many solutions as I could find, but I had no luck. I am quite a noob at this, so I think I am missing something obvious. Perhaps just one line of code that could save me?
...
TECH-TESTER+usd#Tech-tester MINGW64 ~/Desktop/Python-Essentials/PythonIntro
$ ls
python_intro.py
TECH-TESTER+usd#Tech-tester MINGW64 ~/Desktop/Python-Essentials/PythonIntro
$ python python_intro.py
bash: python: command not found
TECH-TESTER+usd#Tech-tester MINGW64 ~/Desktop/Python-Essentials/PythonIntro
$ PATH=$PATH:/c/Python27/
TECH-TESTER+usd#Tech-tester MINGW64 ~/Desktop/Python-Essentials/PythonIntro
$ python python_intro.py
bash: python: command not found
TECH-TESTER+usd#Tech-tester MINGW64 ~/Desktop/Python-Essentials/PythonIntro
$ export PATH="$PATH:/c/Python27"
TECH-TESTER+usd#Tech-tester MINGW64 ~/Desktop/Python-Essentials/PythonIntro
$ python python_intro.py
bash: python: command not found
TECH-TESTER+usd#Tech-tester MINGW64 ~/Desktop/Python-Essentials/PythonIntro
$ python
bash: python: command not found
Sorry if this is such a rookie question, it just seems that everything I find on the internet is above my level to understand, whereas I am at this very basic level.
Meanwhile, I thought Anaconda came with the same py launcher as "official" Python, and offered the same option to install it to somewhere on your PATH.
Try first to check that in a regular CMD.
where python
That will check if python is in the PATH or not.
From there, you can start using python, in a CMD or a git bash session.
Here is the process you can follow to run the Python on your Git Gash.
Launch the program Git Bash in the usual way that you launch Windows programs or VScode. A shortcut for Git Bash was created during installation.
At the command prompt, paste this command export PATH="$PATH:/C/Users/ComputerName/AppData/Local/Programs/Python/Python37-32". That will tell Windows where to find Python. (This assumes that you installed it in export PATH="$PATH:/C/Users/ComputerName/AppData/Local/Programs/Python/Python37-32", as we told you to above.)
Check to make sure that this worked correctly by entering the command python --version. It should say Python 2.7.8 (or 2.7.something), as shown in the figure below.
Assuming that worked correctly, you will want to set up git bash so that it always knows where to find python. To do that, enter the following command:
echo 'export PATH="$PATH:/C/Users/ComputerName/AppData/Local/Programs/Python/Python37-32"' > .bashrc. That will save the command into a file called .bashrc. It will be executed every time git bash launches, so you won’t have to manually tell the shell where to find python again.
Check to make sure that worked by typing exit, relaunching git bash, and then typing python --version again.
Apply above process inside your project folder so that you can use it on VScode.
I have downloaded console2 for windows. Using that I wanted to setup django framework, but console2 couldn't recognize 'pip' as a command. When I tried the same command in windows command prompt, 'pip' was recognized by windows command prompt. Why so?
Check PATH environment variable in console2. It should contains path to the pip executable.
In Windows Command-Prompt the syntax is echo %PATH%
To get a list of all environment variables enter the command set
Here is a screenshot I took.
When I try to use pip in command prompt I get the following error message:
pip is not recognized as an internal or external command, operable program or batch file.
I already checked this thread: How do I install pip on Windows?
All I could find there was I had to add "C:\PythonX\Scripts" to my classpath, where X stands for python version.
As you can see on my screenshot I already have this path. I already tried restarting the computer but that didn't work, o.O. The screenshot also shows my C:\Python27\Scripts folder.
Does anyone know what I am doing wrong?
There is a space before the last path entry, right after the previous semicolon, that is causing the problem.
Go to C:\Python27\Scripts
Now select the url bar and replace whole content with cmd
This way you directly reach to the directory where pip is available in command prompt
Now type pip install Django==1.8.5
it will download and install Djanog
I had the same exact problem, but typing your command in the "Scripts" folder fixed it!
In other words:
Open command prompt (right click windows start menu and click on "Command Prompt (Admin)"
Use "cd" command to change directory to where python is installed, but go to your scripts folder (for me, this is cd C:\Program Files\PythonXX\Scripts where the XX is the version number of Python)
Once in "Scripts" folder, type pip install cython and press enter
what I did is for example in the command prompt or cmd in windows:
py -m pip install pygame
It started working for me when I added ; in PATHEXT after .PY
1) browse here - C:\Python27\Scripts
2) open the cmd window/terminal (shift+'right click')
3) type pip install django
1) open cmd as an administrator
2) enter: cd c:\python27\scripts (go to python and shift right click on folder. Than copy to path)
3) press enter
4) pip install
Add "your python path"\Scripts to PATH variable. See How to set path variable
Don't forget to restart the command prompt.
Now pip will work in any path.
Go to your Python Script Path, copy the path, go to CMD and type cd "paste the path you copied".
type pip --version
You will see the version of pip your system is running.
Check if you have python installed properly.
next install pip using
a) Download get-pip.py to a folder on your computer.
b) Open a command prompt and navigate to the folder containing get-pip.py.
c) Run the following command:
python get-pip.py
Pip is now installed!
Copy the path of executable file in environment variable. It is the Script folder path where python is installed. like
C:Programs\Python\Python35-32\Scripts OR
C:\Users(username)\AppData\Local\Programs**\Python\Python35-32\Scripts**
Restart your command prompt and its done