[FreeBSD] Installing and using Python's virtualenv using Python3

1. Installing Python3.

$ sudo pkg install python36
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 2 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
        python36: 3.6.4
        libffi: 3.2.1_2

Number of packages to be installed: 2

The process will require 103 MiB more space.
15 MiB to be downloaded.

Proceed with this action? [y/N]: y
[1/2] Fetching python36-3.6.4.txz: 100%   15 MiB  15.5MB/s    00:01
[2/2] Fetching libffi-3.2.1_2.txz: 100%   34 KiB  35.3kB/s    00:01
Checking integrity... done (0 conflicting)
[1/2] Installing libffi-3.2.1_2...
[1/2] Extracting libffi-3.2.1_2: 100%
[2/2] Installing python36-3.6.4...
Extracting python36-3.6.4: 100%
Message from python36-3.6.4:

===========================================================================

Note that some standard Python modules are provided as separate ports
as they require additional dependencies. They are available as:

py36-gdbm       databases/py-gdbm@py36
py36-sqlite3    databases/py-sqlite3@py36
py36-tkinter    x11-toolkits/py-tkinter@py36

===========================================================================

2. Installing Python packages tool.

$ sudo pkg install py36-pip
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 2 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
        py36-pip: 9.0.1
        py36-setuptools: 36.5.0

Number of packages to be installed: 2

The process will require 15 MiB more space.
3 MiB to be downloaded.

Proceed with this action? [y/N]: y
[1/2] Fetching py36-pip-9.0.1.txz: 100%    2 MiB   2.6MB/s    00:01
[2/2] Fetching py36-setuptools-36.5.0.txz: 100%  469 KiB 480.2kB/s    00:01
Checking integrity... done (0 conflicting)
[1/2] Installing py36-setuptools-36.5.0...
[1/2] Extracting py36-setuptools-36.5.0: 100%
[2/2] Installing py36-pip-9.0.1...
Extracting py36-pip-9.0.1: 100%
Message from py36-setuptools-36.5.0:

*******************************************************************

  Only /usr/local/bin/easy_install-3.6 script has been installed
  since Python 3.6 is not the default Python version.

*******************************************************************
Message from py36-pip-9.0.1:

============================== !!!! WARNING !!!! ==========================

pip MUST ONLY be used:

 * With the --user flag, OR
 * To install or manage Python packages in virtual environments

Failure to follow this warning can and will result in an inconsistent
system-wide Python environment (LOCALBASE/lib/pythonX.Y/site-packages) and
cause errors.

Avoid using pip as root unless you know what you're doing.

============================== !!!! WARNING !!!! ==========================

3.Installing virtualenv


$ sudo pip-3.6 install virtualenv
Collecting virtualenv
  Downloading virtualenv-15.1.0-py2.py3-none-any.whl (1.8MB)
    100% |################################| 1.8MB 316kB/s
Installing collected packages: virtualenv
Successfully installed virtualenv-15.1.0

4. Installing virtualenvwrapper


$ sudo pip-3.6 install virtualenvwrapper
Collecting virtualenvwrapper
  Downloading virtualenvwrapper-4.8.2-py2.py3-none-any.whl
Collecting virtualenv-clone (from virtualenvwrapper)
  Downloading virtualenv-clone-0.2.6.tar.gz
Collecting stevedore (from virtualenvwrapper)
  Downloading stevedore-1.28.0-py2.py3-none-any.whl
Requirement already satisfied: virtualenv in /usr/local/lib/python3.6/site-packages (from virtualenvwrapper)
Collecting pbr!=2.1.0,>=2.0.0 (from stevedore->virtualenvwrapper)
  Downloading pbr-3.1.1-py2.py3-none-any.whl (99kB)
    100% |################################| 102kB 3.3MB/s
Collecting six>=1.10.0 (from stevedore->virtualenvwrapper)
  Downloading six-1.11.0-py2.py3-none-any.whl
Installing collected packages: virtualenv-clone, pbr, six, stevedore, virtualenvwrapper
  Running setup.py install for virtualenv-clone ... done
Successfully installed pbr-3.1.1 six-1.11.0 stevedore-1.28.0 virtualenv-clone-0.2.6 virtualenvwrapper-4.8.2

5. Configure Shell Startup File
Create a bash startup file, if it doesn't already exist.


$ cp .shrc .bashrc

Updating profile

$ echo 'source ~/.bashrc' >> .profile

Add three lines to your shell startup file(.bashrc).


export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3.6
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/.workspace
source /usr/local/bin/virtualenvwrapper.sh

6. Command Reference

  1. rmvirtualenv Remove an environment, in the WORKON_HOME.
  2. mkproject Create a new virtualenv in the WORKON_HOME and project directory in PROJECT_HOME.
  3. cdproject Change the current working directory to the one specified as the project directory for the active virtualenv.
  4. cdsitepackages Change the current working directory to the site-packages for $VIRTUAL_ENV.
  5. cdvirtualenv Change the current working directory to $VIRTUAL_ENV.
  6. deactivate Switch from a virtual environment to the system-installed version of Python.
  7. workon List or change working virtual environments.
  8. virtualenvwrapper Print a list of commands and their descriptions as basic help output.

Comments

Popular posts from this blog

Python3 + Django + uWSGI + Nginx On FreeBSD

arduino最小構成 (atmega328/8MHz/3.3V/内部クロック)FT232RLにてブートローダーの書き込み

FreeBSD: Configuring Apache to permit CGI