Why has the link from /usr/local/bin/python3 a different path from "which python3"? - bash

I installed python 3.6 before and installed python 3.7.4 today. When I type python3 in command, it opens python 3.6, I want to change it to python 3.7.4.
which python3 shows /Library/Frameworks/Python.framework/Versions/3.6/bin/python3,
but the link in /usr/local/bin/ is :
python3 -> ../../../Library/Frameworks/Python.framework/Versions/3.7/bin/python3
so is the case of pip3. why? ?
How can I change which python3 to python 3.7.4? I don't want to use alias.
I use MacOS 10.14.2

Your OS uses the PATH environment variable to look for the commands you write into the shell, so if you type python3 it will go through the directories listed in this PATH and check if there's your programm. It takes the first matching program and executes it, so in your case the directory /Library/Frameworks/.../3.6/bin is before the directory usr/local/bin, which means that the python3 from /Library/Frameworks/.../3.6/bin will be used.
You need therefore to change this PATH variable:
export PATH="/Users/sky/Documents/software/Montage-master/bin:/usr/share/file/magic/mercurial:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/mysql/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin"
You can put that into your ~/.bash_profile so that it is permanent, and you don't need to set it every time you open a new terminal window.
Note that this will not automatically update your path for the remainder of the session. To do this, you should run:
source ~/.bash_profile

Are you sure have python3.7 intalled?
you can view the folder
cd /usr/bin
Next you search the python's file:
find /usr/bin/ python3
if don´t exist filename python3.7 install
sudo apt install python3.7
sudo apt update

Related

zsh: command not found: jupyter

I installed juypter with pip3. This is the output of pip3 show Jupiter:
Name: jupyter
Version: 1.0.0
Summary: Jupyter metapackage. Install all the Jupyter components in one go.
Home-page: http://jupyter.org
Author: Jupyter Development Team
Author-email: jupyter#googlegroups.org
License: BSD
Location: /Users/myuser/Library/Python/3.8/lib/python/site-packages
Requires: notebook, ipywidgets, ipykernel, qtconsole, nbconvert, jupyter-console
Required-by:
which python3 and which pip3output:
/usr/local/bin/python3
/usr/local/bin/pip3
When I type any Jupiter command zsh returns: command not found: jupyter
I read that I have modify my §PATH variable.
I tried changing it to both
export PATH=/Users/myuser/Library/Python/3.8/lib/python/site-packages
export PATH=/Users/myuser/Library/Python/3.8
If I search for "Jupyter" in Finder I can find for example a jupyter-notebook exec and run it.
How can I use the Jupyter commands from my terminal?
Both PATH definitions you wrote don't make sense, because you have removed the standard directories from the PATH. You need to find the directory, where the executable file juypter resides, and then add this directory to your PATH. This is the same process as with any other program you want to execute through your PATH.
As an alternative, you can always invoke juypter by specifying a path explicitly:
/path/to/your/installed/file/juypter
If you don't know into which directoy pip placed your file, you can try a
find / -name juypter 2>/dev/null
The error redirection is advisable, because you will otherwise get plenty of error messages about directories find is not allowed to cd into.

Cannot create and activate a virtual environment on Git Bash with Python 2.7, Windows

I am using Git Bash on windows with python 2.7 and I want to work in a virtual environment.
When I type
virtualenv venv
Bash says
bash: virtualenv: command not found
That makes me think virtualenv is not installed, then I try to install virtualenv
pip install virtualenv
But again Bash says
bash: pip: command not found
Then by reading this thread python 2.7: cannot pip on windows "bash: pip: command not found" I find out that it cannot find the pip directory, that maybe is the same reason for which it cannot find virtualenv directory.
So I specify the path of pip and I try again to instal virtualenv
python -m pip install virtualenv
It installs virtualenv but then tells
DEPRECATION: Python 2.7 will reach the end of its life on January 1st,
2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python
2.7.
So I go forward and try to activate my virtualenv by typing
virtualenv venv
and as I expected I get the same error of before
bash: virtualenv: command not found
that I try to solve in the same way I did for pip, by typing
python -m virtualenv venv
and this time bash responds with
$ python -m virtualenv venv New python executable in
C:\Users\Tommaso\DJANGO~1\UDEMYD~1\METAGL~2\venv\Scripts\python.exe
Installing setuptools, pip, wheel... done.
So I guess it created my virtualenv named venv, but in my bash terminal I still get the writing "(master)" at the end of the input line, that I guess it means the virtual environment is not active.
How do I activate it?
Solved!
Here is what I did.
First, by following this SO answer, I found out how to make Git Bash use python 3.7 instead of python 2.7 by default:
I opened the file aliases.sh with Notepad++, located at
C:<path where you installed Git Bash>\etc\profile.d\aliases.sh
Under the paragraph
--show-control-chars: help showing Korean or accented characters
I added these lines indicating where the two versions of python I want to switch are located
alias python2='C:/<installation_path_of_python_2.7>/Python 2.7/python.exe'
alias python='C:/<installation_path_of_python_3.7>/Python 3.7/python.exe'
alias pip='C:/<installation_path_of_python_3.7>/Phyton/Scripts/pip.exe'
alias virtualenv='C:/<installation_path_of_python_3.7>/Phyton/Scripts/virtualenv.exe'
You don't really need the last 2 ones, but it will help you a lot, since it enables Git Bash to call pip, virtualenv and other scripts without writing python -m before the name of the script.
You can check out if you did right by typing
python -i
It should return you the latest python version you specified.
Then if I type
python -m virtualenv venv
It installs the virtual environment in the current directory
To activate that, just type
. venv/scripts/activate
If it works, you should see
(venv)
near to your active input line.
To deactivate it just type
deactivate
I had the same problem before. The solution is to install virtualenv first using pip. Then:
enter virtualenv nameOfTheEnvironment
nameOfTheEnvironment\Scripts\activate
You should see something like:
C:\Users\bamidele\Documents\DjangoProjects>virtualenv venv
created virtual environment CPython3.7.2.final.0-64 in 15334ms
creator CPython3Windows(dest=C:\Users\bamidele\Documents\DjangoProjects\venv, clear=False, global=False)seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, via=copy, app_data_dir=C:\Users\bamidele\AppData\Local\pypa\virtualenv\seed-app-data\v1.0.1)activators BashActivator,BatchActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
C:\Users\bamidele\Documents\DjangoProjects>venv\Scripts\activate
(venv) C:\Users\bamidele\Documents\DjangoProjects>```
I hope this solves your problem.
In git bash, cd into the virtual environment(venv) directory of your project and use this command
source ./Scripts/activate
to activate virtual environment(venv)
You can go
cd venv\Scripts
path. Then:
Run the command
activate
This run on my Flask project.

need to manually create symlinks every time i install something

For example, I'm trying to install pipenv using the following commands:
$ pip3 install --user pipenv
$ cd ~/Documents/myproject
$ pipenv install requests
zsh: command not found: pipenv
It seems that the issue can be resolved if I run sudo ln -s ~/.local/bin/pipenv /usr/bin. Is this a safe thing to do? I've also been having this issue with several other packages, like tensorboard and xflux. Is there something wrong with my system that makes it such that I need to manually create a symlink every time? How can I change things so that packages can install normally without me having to do this every time?
The problem you are having is that the tools you are installing are being installed in non-standard locations and are not being included in your PATH. One way to resolve this would be to include the paths in your PATH environment variable. In order for these programs to be in your path every time you login, do this (assuming you are using zsh as your shell):
1) Open ~/.zshrc using vim or any other editor:
vim ~/.zshrc
2) Append the following to this file:
export PATH=$PATH:/path/to/dir/containing/pipenv
Remember to replace /path/to/dir/containing/pipenv with the appropriate path.
3) Source your ~/.zshrc so that the path is included in your current session:
source ~/.zshrc
4) Now everytime you login, the paths should be available in your environment and you won't need to create symlinks.

Golang installation

I just followed the installation guide for golang (ubuntu 16).
I extracted the archive at /etc/usr
I added env variable in /home/user/.profile
I just tested a basic go build on the hello world code.
I get the following error:
The program 'go' is currently not installed. You can install it by typing: sudo apt install golang-go
Why does it ask me to install it (again?)?
open the go documentation download
https://go.dev/dl/
choice your os and go version
download then extract the file
extract the file
open the file and open the terminal
6.Add /usr/local/go/bin to the PATH environment variable.
export PATH=$PATH:/usr/local/go/bin
then check the go version
go version
The location of the binary go is not in your path. Ubuntu does not find it and suggests to install it. Add this line to your file /etc/profile, or better $HOME/.profile:
export PATH=$PATH:/usr/local/go/bin
This is documented in the docs: https://golang.org/doc/install#install
If you want to try this solution before editing any files, you can just execute the above command and try to execute the go command in the shell.
There are paths which needs to be set correctly for you go installation to work
GOROOT points to directory where go is installed
export GOROOT=/usr/lib/go
GOPATH points to you workspace directory
export GOPATH=$HOME/go
These paths need to be added in global path variable.
export PATH=$PATH:$GOROOT/bin
You need to put the go executable in your system path. which you can do by
export PATH=$PATH:/etc/usr/go/bin
You can put the same in /home/user/.profile
just use asdf for installation. You can have several version also :D
Docs: https://asdf-vm.com/#/core-manage-asdf
downlaod the installer form enter link description here, choose intaller for linux that suit your device and then you go to your CLI and use wget or curl :
$ wget https://storage.googleapis.com/golang/go1...
and then extract the file to /usr/local :
$ tar -C /usr/local -xzf go1...
add path binary Go to PATH environment variable :
$ echo "export PATH=$PATH:/usr/local/go/bin" >> ~/.bashrc
$ source ~/.bashrc
and then use go version to check if the Go already installed
If You are using linux then open your terminal and run this command.
sudo apt install golang-go
This command will Install Go lang. in your system. ThankYou
Steps for Go installation:
sudo apt-get update && sudo apt-get -y upgrade    
wget https://dl.google.com/go/go1.17.5.linux-amd64.tar.gz
sudo tar -xvf go1.17.5.linux-amd64.tar.gz
sudo mv go /usr/local/
export GOROOT=/usr/local/go
Add in .bashrc
vi .bashrc
export GOPATH="/root/go"
export GOROOT=/usr/local/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
Download latest version from https://golang.org/doc/install
tar -xzf go1.15.7.linux-amd64.tar.gz
move to /usr/lib/ to folder with version number
sudo mv go /usr/lib/go-1.15
create symkink link on /usr/bin/
ln -s /usr/lib/go-1.15/bin/go /usr/bin/go

Issue with activating virtualenv

I installed python environment by means of commands:
SYS_INSTALL="apt-get install -y"
PIP_INSTALL="pip install"
# Be sure to install setuptools before pip to properly replace easy_install.
$SYS_INSTALL git
$SYS_INSTALL python-dev
$SYS_INSTALL python-setuptools
$SYS_INSTALL python-pip
$PIP_INSTALL virtualenv
also was able to create new virtual environment:
virtualenv .env
However, after running a command like:
. .env/bin/activate
I got
-bash: .env/bin/activate: No such file or directory
After reviewing folder .env/bin I found only one python file. Whole list of files here:
.env/lib:
python2.7
.env/include:
python2.7
.env/bin:
python
What is the issue here?
SOLUTION add --always-copy
virtualenv .env --always-copy
For me it works when I do these steps:
Go to the directory/folder that you want
run virtualenv .env
then run source .env/bin/activate
The accepted answer is incomplete! The suggested code left out your error, but didn't comment on it.
The command . .env/bin/activate would indeed do the same as source on the file activate in the folder .env/bin. In fact, apparently the command "source" is an alias for the command ".", and not the other way around. Note that . here has a space after it, and used differently from the . discussed below (which makes files and folders hidden).
What I notice is that you are calling your folder .env, which is not standard practice. Files and folders preceded by . are made "hidden" by Mac OS X. Standard practice is to call a virtual environment directory env or venv, and to call the virtual environment specification file .env.
So, if your spec file is called .env and your virtual environment directory is called env, you can run either
source env/bin/activate
or
. env/bin/activate.
I had the same issue and the following steps resolved it:
$mkdir annotateNLP
$cd annotateNLP
$python -m venv env
$source env/Scripts/activate
Try these commands in the terminal:
$ mkdir djangoapp
$ cd djangoapp
$ python3 -m venv myvenv
$ source myvenv/bin/activate
You can't go straight into activate command without first creating your virtual environment.
you forgot to include source before activating command is
source env/bin/activate
this question is similar to your's
virtualenv is not compatible with this system or executable
where it creates virtualenv but,python file instead of activate in bin
After going to your virtual environment folder .\Scripts\activate.
In my case, I need to install
sudo apt-get install python3-venv
$ virtualenv env
$ cd env/Scripts/
$ . activate
I was facing this same issue. I uninstalled the virtualenv in Ubuntu and then I installed it again. After this nonsense, it works and now I am able to activate my virtualenv through -$source py3/bin/activate.
If installed venv on a Windows machine, run this command (assuming you are in the working directory that has your venv folder):
In bash terminal: source venv/Scripts/activate
In cmd terminal:
venv\Scripts\activate
where venv is the folder name for your virtual environment
For windows using git bash, run the below command:-
source env\Scripts\activate

Resources