Sphinx-quickstart doesn't work - bash

I am trying to install sphinx on a remote machine.
Since I don't have an access to the root, I did this:
$bash
$mkdir -p ~/local/lib/python2.7/site-packages
$export PYTHONPATH=$PYTHONPATH:~/local/lib/python2.7/site-packages
$export PATH=$PATH::~/local/lib/python2.7/site-packages
$easy_install -U --prefix=$HOME/local Sphinx
But apparently, $easy_install doesn't build sphinx-quickstart; when I type
$sphinx-quickstart
I get the following message:
bash: sphinx-quickstart: command not found
I tried
find $HOME -name sphinx-quickstart
and no result was found. However, I can import sphinx inside python:
$python
And then
>>import sphinx
works. Any idea why sphinx-quickstart doesn't work?

An alternative way to invoke sphinx-quickstart is to explicitly load Sphinx's quickstart module. For Sphinx v1.7+:
python -m sphinx.cmd.quickstart
For older versions of Sphinx:
python -m sphinx.quickstart
For example:
$ /c/Python35/python -m sphinx.quickstart
Welcome to the Sphinx 1.6.2 quickstart utility.
...

I found the solution in this webpage:
User (root/sudo free) installation of Python modules.
In section 3. Python 2.6+ he mentioned that the command line commands are in
~/local/bin
Although I had put ~/local/lib/python2.7/siste-packages in the path, the ~/local/bin directory was not in the path. So all I did
$export PYTHONPATH=$PYTHONPATH:~/local/bin
and now it works.
I don't know why find $HOME -name sphinx-quickstart did not find sphinx-quickstart

In MacOS (Catalina) and zsh:
I installed sphinx with brew and had the same problem as you.
Solution:
Installed it with conda as conda install sphinx and now it works for me
$ sphinx-quickstart
Welcome to the Sphinx 2.3.0 quickstart utility.
Installation Guide

Note, if you're in a virtual environment and using poetry to run
poetry run py -m sphinx.cmd.quickstart
where py is the python launcher for Windows.

Have added an answer for installation on macOS using brew here
For new users, installing with brew gives the following caveats:
==> sphinx-doc
sphinx-doc is keg-only, which means it was not symlinked into /usr/local,
because this formula is mainly used internally by other formulae.
Users are advised to use `pip` to install sphinx-doc.
If you need to have sphinx-doc first in your PATH, run:
echo 'export PATH="/usr/local/opt/sphinx-doc/bin:$PATH"' >> ~/.zshrc
Running the echo command:
echo 'export PATH="/usr/local/opt/sphinx-doc/bin:$PATH"' >> ~/.zshrc
should fix the issue.
Don't miss source-ing the .zshrc after the updating it:
source ~/.zshrc

Related

How to change pythonpath to use Python 3.9 and venv

I am trying to get to grips with Python on my Mac running OS X 10.15.7 Catalina.
My goal is to be able to run a program requiring Python 3.9 and associated libraries, in its own virtual environment, using venv.
My quest has led me over many rocky paths and blind alleys - including via Anaconda and Brew.
I am running zsh - specifically oh-my-zsh ys version. If that's important. Most online forums and tutorials assume bash. I would prefer to do all in zsh to avoid having to edit both zsh and bash profiles.
Current Shell Outputs
$ python -V
Python 2.7.16
$ which python
/usr/bin/python
$ python3 -V
Python 3.8.2
$ which python3.8
python3.8 not found
$ which python3.9
python3.9 not found
$ python3 -m -V
/Library/Developer/CommandLineTools/usr/bin/python3: No module named -V
Pausing there ..
Py 2.7 is the OS X system Python and I don't want to do anything with it.
It is odd that python3 -m returns a reference to the CLI tools. See below. The only location for py3.8 is in the CL tools.
What pythons do I have (output below is edited so as to show only main directories and Files)?
$ locate python
/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/3.7/bin/python3
/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/bin/python3.8
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
/Library/Developer/CommandLineTools/usr/bin/python3.8
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3-config
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9-config
/Library/Frameworks/Python.framework/Versions/3.9/share/man/man1/python3.1
/Library/Frameworks/Python.framework/Versions/3.9/share/man/man1/python3.9.1
/Library/Frameworks/SAVI.framework/Versions/A/Frameworks/Python.framework/Versions/3.6/lib/python3.6
/usr/bin/python
/usr/bin/python-config
/usr/bin/python2
/usr/bin/python2.7
/usr/bin/python2.7-config
/usr/bin/python3
/usr/bin/pythonw
/usr/bin/pythonw2.7
/usr/lib/libpython.dylib
/usr/lib/libpython2.7.dylib
/usr/lib/python2.7
/usr/local/bin/python3
/usr/local/bin/python3-config
/usr/local/bin/python3.9
/usr/local/bin/python3.9-config
/usr/share/file/magic/python
/usr/share/man/man1/python.1
/usr/share/man/man1/python2.7.1
/usr/share/man/man1/pythonw.1
/usr/share/man/man1/pythonw2.7.1
/usr/share/vim/vim81/autoload/python3complete.vim
/usr/share/vim/vim81/autoload/pythoncomplete.vim
/usr/share/vim/vim81/ftplugin/python.vim
/usr/share/vim/vim81/indent/python.vim
/usr/share/vim/vim81/syntax/python.vim
/usr/share/zsh/5.7.1/functions/_bpython
/usr/share/zsh/5.7.1/functions/_python
/usr/share/zsh/5.7.1/functions/_python_modules
WHAT ABOUT PIP?
$ pip3
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
$ pip3 install --upgrade pip
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pip in ./Library/Python/3.8/lib/python/site-packages (20.3.3)
Note two points
Although the wrapper warning comes up, PIP 20.3.3 is latest version which I have upgraded. Probably the reason for the warning is in the next lines, which suggest that PIP3 is being invoked from the CL Tools.
2; The ‘normal site-packages is not writeable’ error is supposed to be cured by specifying the Path. I have tried already to specify the correct path - see below - but this has not cured the problem and is another major reason for asking the question at the end of this post.
$ python -m pip
/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: No module named pip
$ python3 -m pip
Usage:
/Library/Developer/CommandLineTools/usr/bin/python3 -m pip <command> [options]
$ which pip3
/usr/bin/pip3
$ locate pip3
/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/3.7/bin/pip3
/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/3.7/bin/pip3.7
/Library/Developer/CommandLineTools/usr/bin/pip3
/Library/Developer/CommandLineTools/usr/bin/pip3.8
/Library/Frameworks/Python.framework/Versions/3.9/bin/pip3
/Library/Frameworks/Python.framework/Versions/3.9/bin/pip3.9
/usr/bin/pip3
/usr/local/bin/pip3
/usr/local/bin/pip3.9
SYSTEM FILES
~/.zprofile contents - edited a few times to remove references to virfualenv and penv, both originally installed with brew and now removed. I have run brew uninstall and brew remove to try to clean everything up but may not have succeeded.
Start
# THIS FILE COMMENTED OUT RH 21DEC20
## Setting PATH for Python 3.9
## The original version is saved in .zprofile.pysave. **Note in this post only - cannot find this file**
PATH="/Library/Frameworks/Python.framework/Versions/3.9/bin:${PATH}"
export PATH **Note in this post only - this does not seem to have worked - see above Python3 -V**
# export WORKON_HOME=~/.virtualenvs
# mkdir -p $WORKON_HOME
# . ~/.pyenv/versions/3.9.0/bin/virtualenvwrapper.sh
# eval "$(pyenv init -)"
# # AND THESE LINES ADDED FOLLOWING STACKOVERFLOW Q 33216679 **Note in this post only - commented out as shell threw errors .’cannot find virtualenvwrapper.sh**
# export WORKON_HOME=$HOME/.Envs
# # export VIRTUALENVWRAPPER_PYTHON=$/usr/bin/python3
# export VIRTUALENVWRAPPER_PYTHON=$/usr/local/bin/python3
#source $HOME/.local/bin/virtualenvwrapper.sh
END
Finally a word about Brew. Many tutorials advised the use of Brew to install Python, pyenv, and libraries etc. I did that and successfully created a test environment, but could not the utilise it. I have then removed as much as possible in order to get back to a ‘clean’ state to work with.
Current brew status is
$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!
Warning: Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected dylibs:
/usr/local/lib/libdvdcss.2.dylib
/usr/local/lib/libfuse.0.dylib
/usr/local/lib/libulockmgr.0.dylib
Warning: Unbrewed header files were found in /usr/local/include.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected header files:
/usr/local/include/ulockmgr.h
Warning: Unbrewed .la files were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected .la files:
/usr/local/lib/libulockmgr.la
Warning: Unbrewed static libraries were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected static libraries:
/usr/local/lib/libfuse.a
/usr/local/lib/libulockmgr.a
SUMMARY
My first goal is to set Py3.9.x as default for new projects. I think also this would require/imply that pip and other commands run from v3.9 and not any other version or location. Must admit to being hazy about that.
Then I want to be able to create a virtual environment into which I can put the program I want to run and its associated libraries and packages. Doing this implies using terminal, but I need to know which directory I need to be in to run which commands.
At this point I have also been running into confusion with tutorials on how to create a virtual environment. From what I have read I think I should use venv over pyenv. What is not clear is whether I run the venv command (s) from root, or whether I have to create and cd to a different location, and if so what.
Any help in
1 Changing the default Python to 3.9
2 Creating a venv to use v3.9.
3 What commands to run where.
Will be greatly appreciated. Please keep it simple and don't assume any prior knowledge!
This is what I would do :
# For 1 Changing the default python to 3.9
cd /usr/local/bin
sudo ln -fs /Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9 python3
sudo ln -fs python3 python
# And make sure /usr/local/bin is before (/usr/bin and /Library/Developer/CommandLineTools/usr/bin) in your $PATH
# For 2 Creating a venv to use v3.9
/usr/local/bin/python3.9 -m venv /tmp/python3.9-venv

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

Setting PATH with multiple Python versions under MacOS

I would like to make the version of python 2 packaged with MacOS the system default Please show me the recommended approach.
I have installed a Python 3 version from miniconda/anaconda, and my current default Python is:
$ which python
/Users/PatrickT/miniconda3/bin/python
I do not want this to be the default Python anymore. The dilemma is: if I remove conda from the PATH, I can access the Python version packaged with the OS, but then I can no longer access the conda Python...
It sounds like you might want a python version manager, such as https://github.com/yyuu/pyenv
I can't vouch for this specific tool, but there are several similar utilities for ruby (rbenv, rmv) that are great.
OS X (or is it macOS now?) come with an installed version of Python. You almost certainly don't want to mess with that since updates to the OS will likely overwrite your changes. You may want to consider a tool called homebrew for OS X -- it lets you install specific versions of tools like python and manages them externally to the built-in versions.
Edit the .bash_profile
$ nano ~/.bash_profile
1. delete any reference to "export PATH=" to non-default-os python.
2. set up aliases to alternative python versions.
In other words, replace e.g. this:
# added by Miniconda3 4.0.5 installer
export PATH="/Users/PatrickT/miniconda3/bin:$PATH"
with this:
## create alias to miniconda/anaconda
## to make conda command accessible, first run: condainit
alias condainit='export PATH="/Users/PatrickT/miniconda3/bin:$PATH"'
## create alias to other python versions
alias pyconda='/Users/PatrickT/miniconda3/bin/python'
alias python3='/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}'
## After installing pyenv with homebrew and run $ brew info pyenv
## set the following, according to the "caveat instructions":
if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi
Source the .bash_profile:
$ source ~/.bash_profile
To access conda commands run this in the terminal:
$ condainit
$ conda info -e
To access the Python3 provided by conda, type:
$ pyconda
To access the Python3 installed via the dmg, type:
$ python3
To access the default OS-provided python (currently Python 2.7), type:
$ python
Among other sources, the following was particularly useful: Using two different Python Distributions

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

How do I update zsh to the latest version?

I recently switched to zsh on my Terminal.app on my OS X machine successfully. The version number of zsh is 4.3.11.
If you're using oh-my-zsh
Type omz update in the terminal
Note: upgrade_oh_my_zsh is deprecated
If you have Homebrew installed, you can do this.
# check the zsh info
brew info zsh
# install zsh
brew install --without-etcdir zsh
# add shell path
sudo vim /etc/shells
# add the following line into the very end of the file(/etc/shells)
/usr/local/bin/zsh
# change default shell
chsh -s /usr/local/bin/zsh
If you're not using Homebrew, this is what I just did on MAC OS X Lion (10.7.5):
Get the latest version of the ZSH sourcecode
Untar the download into its own directory then install: ./configure && make && make test && sudo make install
This installs the the zsh binary at /usr/local/bin/zsh.
You can now use the shell by loading up a new terminal and executing the binary directly, but you'll want to make it your default shell...
To make it your default shell you must first edit /etc/shells and add the new path. Then you can either run chsh -s /usr/local/bin/zsh or go to System Preferences > Users & Groups > right click your user > Advanced Options... > and then change "Login shell".
Load up a terminal and check you're now in the correct version with echo $ZSH_VERSION. (I wasn't at first, and it took me a while to figure out I'd configured iTerm to use a specific shell instead of the system default).
As far as I'm aware, you've got three options to install zsh on Mac OS X:
Pre-built binary. The only one I know of is the one that ships with OS X; this is probably what you're running now.
Use a package system (Ports, Homebrew).
Install from source. Last time I did this it wasn't too difficult (./configure, make, make install).
A simple script or execute following commands in terminal
# 1. download (currently the latest version is 5.8) and extract
wget https://sourceforge.net/projects/zsh/files/latest/download -O ./zsh-latest.tar.xz
mkdir zsh-latest
tar -xf zsh-latest.tar.xz -C zsh-latest --strip-components=1
cd zsh-latest
# 2. config, build, install
./configure
make -j4
sudo make install
which zsh
PS: If you fail to build, it probably due to missing necessary libraries. Just install libraries as the error message suggests. E.g, I didn't have ncurses:
sudo apt install ncurses-devel # for Ubuntu
sudo yum install ncurses-devel # for CentOS/Redhat
omz update gave me following error:
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
This is an issue with git, where after upgrading to Mac OS Ventura (13.0.1). git command gave me above error.
Solution:
Download and install the 'Command Line Tools' package to fix 'git'
xcode-select --install
This will pop a dialogue box. Select "Install".
More details here: https://apple.stackexchange.com/a/254381
omz update worked successfully after this for me
I just switched the main shell to zsh. It suppresses the warnings and it isn't too complicated.

Resources