The other day, I tried using Anaconda in a local environment, but I thought, "Is it possible to display this in a browser ...?", So I decided to create an environment where Django can be used.
This time, I went from launching Vagrant's box to displaying the Django virtual server screen on the browser.
Eventually, Fill out the form in the browser → Machine learning model is calculated on the server side based on the sent data → Return the result to the browser I would like to make an app like that.
Host OS: Windows10 Guest OS: Centos7 (Vagrant)
This is based on Hello World in Vagrant + Python3 + Django environment. Work at the command prompt.
vagrant box add centos/7
vagrant init centos/7
Add the following two lines to the generated Vagrantfile.
config.vm.synced_folder "./", "/home/vagrant/work"
config.vm.network "forwarded_port", guest: 8000, host: 18000
Go back to the command prompt and start vagrant.
vagrant up
vagrant ssh
Only python2 series is included by default, so I want to include python3. Considering the future, I thought it would be a good idea to use version control software, so I decided to use pyenv. It seems to be deprecated ... It is based on Installing Python3 using pyenv.
Prepare everything you need. From here, I'm working on Teraterm. vagrant ssh may be fine.
$ sudo yum groupinstall "Development tools"
$ sudo yum install gcc zlib-devel bzip2 bzip2-devel readline readline-devel sqlite sqlite-devel openssl openssl-devel git
Install pyenv
$ git clone https://github.com/yyuu/pyenv.git ~/.pyenv
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
$ source .bash_profile
Update pyenv to the latest version
$ pyenv --version
pyenv 1.2.3-43-g35f7ef8
$ pyenv install --list #A lot of python that can be installed comes out
$ pyenv install 3.8.3 #Make sure you have the version you want to use and install
$ pyenv global 3.8.3
Check the version of pyenv, python
$ pyenv versions
system
* 3.8.3 (set by /home/vagrant/.pyenv/version)
$ python --version
Python 3.8.3
Delete old Django (hopefully you can confirm it doesn't exist)
$ python -c "import django; print(django.__path__)"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named django
Install virtualenv, virtualenvwrapper, django
$ pip install virtualenv
$ pip install virtualenvwrapper
$ pip install Django
Django version check
$ python -m django --version
3.0.6
SQLite3, which is included by default in Vagrant, seems to be an old version, and if you try to start the server as it is, an error will occur, so install a new one. Introduction to Django (Tutorial)-Introduction to Tohoho's WWW was helpful.
$ yum install -y wget gcc make
$ wget https://www.sqlite.org/2019/sqlite-autoconf-3290000.tar.gz
$ tar zxvf ./sqlite-autoconf-3290000.tar.gz
$ cd ./sqlite-autoconf-3290000
$ ./configure --prefix=/usr/local
$ make
$ make install
$ cd ..
$ rm -rf ./sqlite-autoconf-3290000 ./sqlite-autoconf-3290000.tar.gz
$ mv /usr/bin/sqlite3 /usr/bin/sqlite3_old
$ ln -s /usr/local/bin/sqlite3 /usr/bin/sqlite3
$ echo 'export LD_LIBRARY_PATH="/usr/local/lib"' >> ~/.bashrc
$ source ~/.bashrc
Create a project under / home / vagrant / work. Since it was set with Vagrantfile, the files and apps created here will be shared locally and in the virtual environment.
config.vm.synced_folder "./", "/home/vagrant/work"
Django project creation
$ cd /home/vagrant/work
$ django-admin startproject mysite #mysite is your favorite project name
$ cd mysite #Move into project
$ python manage.py runserver 0:8000 #Server startup
Then type http://127.0.0.1:8000 into your browser to open the page!
Initially, the server was running, but the browser couldn't display anything, which was a lot of work. I'm glad I managed to solve it on my own. However, I feel like I've done it, but this is just the preparation stage. There seems to be a long way to go until the application is complete.
From Vagrant to Django installation in general: Hello World in Vagrant + Python3 + Django environment
SQLite3 version upgrade: Introduction to Django (Tutorial)-Introduction to Tohoho's WWW
Installation and management of python: Installing Python3 using pyenv
Recommended Posts