Building a Hy environment for Lisper who hasn't touched Python

This article is the 15th day article of Lisp Advent Calendar 2019.

Summary of this article

Hy is a Clojure-like Lisp dialect that runs on Python's Virtual Machine. For Lisper (mainly Clojurian) who has never touched Python, I will focus on how to build a Hy environment.

Target audience

For an introductory document on Hy itself, please refer to the official tutorial or the one written by the predecessor.

Environment

Install python

For Windows 10

It's easy to download and install the installer from python.org. Suddenly, the latest installer that can be downloaded from the top page of python.org is the 32-bit version (as of December 2019). Be careful not to install it unless you are in a 32-bit environment.

2019-12-10_22h14_25.png

For MacOS

It seems common to install Homebrew and then use the brew command.

$If you check the installable version with brew info python, 3.7.Was 5(2019/12/At 13 points)。



 Location of Python 3 (3.7.5) installed by Homebrew

/usr/local/bin/python3


 location of site-packages

/usr/local/lib/python3.7/site-packages


## Building a virtual environment

 Even if I install a third-party module in the site-packages of Python itself, it works, but
 By using different virtual environments for each project, you can avoid polluting the original environment and avoid affecting other projects.
 If you create a virtual environment using the ``` venv``` command that comes by default, it will be created by executing the following under the directory you want to create.

$ python -m venv


 If the dependencies of the third-party modules described below are messed up while using the virtual environment, just throw them away and recreate them.

 To enable / disable the virtual environment, use the ```activate``` and `` `deactivate``` commands.
 The location of ```activate``` in venv depends on the Shell and OS, so [venv --- Create Virtual Environment](https://docs.python.org/ja/3/library/venv. See "Commands for enabling the virtual environment" in html).


## Module installation

 When you install Python, the Standard Library (https://docs.python.org/ja/3/library/index.html) is installed with you and you can use them from Hy. Since Python is a language with a built-in battery, you can do a lot with the standard library alone.

 If you want to use a third-party module other than the standard library, use the package management tool [pip](https://docs.python.org/ja/3/installing/index.html) to install it in your virtual environment. I will.
 Basically, all Python modules (almost) work on Hy.
 Of course, modules written in Hy will work if they are the same version (although I rarely see them ...).
 Look for third-party Python modules at [PyPI](https://pypi.org/).
 Occasionally, there are Python modules that aren't registered with PyPI, but I'll show you how to install them later (for those managed in the GitHub repository).

 You can also install the scientific calculation library Anaconda and manage modules with `` `conda```.
```pip```I will not install it in this article as it may damage the environment when used in combination with.

 ```activate``` the virtual environment and install the module with `` `pip install <module name>` ``.
 If you want to install all at once, write requirements.txt with the module names separated by line breaks and run `` `pip install -r requirements.txt```. By convention, it is named requirements.txt, but you can name it something else.


#### **`requirements.txt`**
```text

hy
openpyxl
PySide2

You can also specify a specific version.

requirements.txt


hy==0.17.0
openpyxl==3.0.2
PySide2==5.13.2

If the module is only in the GitHub repository

pip install git+https://github.com/hoge/fuga.git

To do. You can also include this in requirements.txt.

If you want to see a list of third-party modules installed in that environment, run `` `pip freeze```.

pip freeze > requirements.If you write it out like txt, it will be easier to recover even if the environment is corrupted.



## Editor / IDE

 Few editors / IDEs have Hy plugins yet. As far as I know, there are only three:

* Emacs
 * [hy-mode](https://melpa.org/#/hy-mode)

* Vim
 * [vim-hy](https://github.com/hylang/vim-hy)

* Visual Studio Code
 * [vscode-hy](https://marketplace.visualstudio.com/items?itemName=xuqinghan.vscode-hy)

# How to make a package

 If you want to layer your own applications and libraries, creating a package makes it easier to manage.

hy ─┬─ hoge ─┬─ fuga ─┬─ init.hy . │ . └─ piyo │ └─ bar.hy │ ├─ init.hy . └─ foo.hy


 When the `` `hy``` directory is added to the environment variable [PYTHONPATH](https://docs.python.org/ja/3/using/cmdline.html#envvar-PYTHONPATH) in the above figure,
 By putting \ _ \ _ init \ _ \ _. Hy in each directory under hoge


#### **`example_import.hy`**
```hylang

(import hoge)  ;;hoge__init__.hy is imported
(import hoge.foo)
(import hoge.fuga)  ;; hoge/fuga__init__.hy is imported
(import hoge.fuga.bar)

Can be written as The structure of this package is similar to Python.

Python Tutorial> 6. Modules> 6.4. Packages

Summary

Let's have a good Hy life.

Recommended Posts

Building a Hy environment for Lisper who hasn't touched Python
[Mac] Building a virtual environment for Python
Building a Python development environment for AI development
Building a Python virtual environment
Building a Python virtual environment
Write about building a Python environment for writing Qiita Qiita
Building a Docker working environment for R and Python
Procedure for building a CDK environment on Windows (Python)
Building a Python environment for programming beginners (Mac OS)
Memo for building a machine learning environment using Python
Building a Python environment on Mac
Building a python environment for artificial intelligence (Chainer / TensorFlow / CSLAIER)
Building a Python environment on Ubuntu
Building a virtual environment with Python 3
[Python] Building a virtual python environment for the pyramid tutorial (summary)
Building a Docker working environment for R and Python 2: Japanese support
How about Anaconda for building a machine learning environment in Python?
Building a Windows 7 environment for getting started with machine learning with Python
From building a Python environment for inexperienced people to Hello world
[Pyenv] Building a python environment with ubuntu 16.04
Building a Python3 environment with Amazon Linux2
Let's create a virtual environment for Python
Building a Python 3.6 environment with Windows + PowerShell
Building a conda environment for ROS users
A modern environment building procedure for those who want to get started with Python right away
Building a virtual environment for Mayavi dedicated to Python 3.6, Anaconda, Spyder users
Selenium + WebDriver (Chrome) + Python | Building environment for scraping
Building an environment for executing Python scripts (for mac)
Building an Anaconda environment for Python with pyenv
Building a Python environment with WLS2 + Anaconda + PyCharm
[Python] Web development preparation (building a virtual environment)
Think about building a Python 3 environment in a Mac environment
Commands for creating a python3 environment with virtualenv
Procedure for creating a Python quarantine environment (venv environment)
A memo for creating a python environment by a beginner
Building a Python environment on a Sakura VPS server
Create a Python environment
Python environment for projects
Recommendation of building a portable Python environment with conda
Building a training environment for penetration testing using Naumachia
Build a python environment for each directory with pyenv-virtualenv
Building an environment for natural language processing with Python
Building and enabling a python virtual environment, etc. (venv)
conda memorandum: Building a Python environment with supercomputer ITO
Building a Python environment on a Mac and using Jupyter lab
Summary from building Python 3.4. * From source to building a scientific computing environment
[Note] List of basic commands for building python / conda environment
The shortest memo for building a python environment that takes less than 5 minutes to work.
Python environment construction For Mac
Python3 environment construction (for beginners)
[For organizing] Python development environment
Build a Python environment offline
Precautions that must be understood when building a PYTHON environment
Create a virtual environment for python on mac [Very easy]
Until building a Python development environment using pyenv on Ubuntu 20.04
Build a python environment on CentOS 7.7 for your home server
Create a Python environment for professionals in VS Code on Windows
Create a Python execution environment for Windows with VScode + Remote WSL
Build and test a CI environment for multiple versions of Python
Build a local development environment for Lambda + Python using Serverless Framework
Python environment construction 2016 for those who aim to be data scientists