Note: Start Anaconda, enter the Python virtual environment, and connect locally to MongoDB.

※memorandum

Move to app under development

Enter the directory with cd with terminal.

Launch Anaconda

↓ Enter the following to move from base (current location) to the virtual environment (in my case, the created name is py3_aaaa).

python


$ (base) lancai@oja % source activate py3_aaaa #py3_aaa: Created virtual environment name

↓ Because this development environment is API uvicorn prog: app --reload --host 0.0.0.0 --port 8100 Enter prog replaced with api (below)

python


$ (base) lancai@oja % uvicorn api:app --reload --host 0.0.0.0 --port 8000

This completes the connection!

Check when you can't connect to MongoDB locally

In the app directory under development ..> src> db> connect.py, Check if the set username and password are described. If not, add it.

python


from pymongo import MongoClient

#DB connection
def get_connect():
    #mongoDB local connection
    client = MongoClient("mongodb://(* Username here):(Password here)@localhost:27017/")
    #DB used (specify DB)
    db = client.(* DB name is entered here)
    return db

Enter the following command on terminal

:terminal:terminal:


$ uvicorn api:app --reload --host 0.0.0.0 --port 8000

[Supplement] How to check information such as username set in MongoDB

① Move to the location where the docker-composer.yml file of the application under development is placed on the terminal

② ↓ Refer to "cat" at the terminal.

terminal


$ cat docker-compose.yml

③ ↓ environment: It is described in the part ^ ^

terminal


    environment:
      MONGODB_USERNAME: *****
      MONGODB_PASSWORD: *****
      MONGODB_HOSTNAME: *****db
      # VIRTUAL_HOST: ""
      # LETSENCRYPT_HOST: ""
      # LETSENCRYPT_EMAIL: "*********@gmail.com"

Recommended Posts

Note: Start Anaconda, enter the Python virtual environment, and connect locally to MongoDB.
From Python environment construction to virtual environment construction with anaconda
Create a Django project and application in a Python virtual environment and start the server
Install django on python + anaconda and start the server
[Anaconda] Activate the virtual environment
Build a Python environment and transfer data to the server
Overview of Python virtual environment and how to create it
Building a virtual environment for Mayavi dedicated to Python 3.6, Anaconda, Spyder users
Change Python 64bit environment to 32bit environment with Anaconda
About the virtual environment of python version 3.7
[Python] Create a virtual environment with Anaconda
Migration from Python2 to Python3 (Python2 is rebuilt as a virtual environment and coexists)
Try to build python and anaconda environment on Mac (by pyenv, conda)
Start the webcam to take a still image and save it locally
How to add python module to anaconda environment
Add a Python virtual environment to VSCode
If you want to enter the virtual environment with jupyter, nb_conda_kernels is recommended
Introduction to Python Let's prepare the development environment
How to create a Python virtual environment (venv)
[Node-RED] Execute Python on Anaconda virtual environment from Node-RED [Anaconda] [Python]
[Note] How to write QR code and description in the same image with python
Python: Creating a virtual environment (venv), starting and stopping
Build a python virtual environment with virtualenv and virtualenvwrapper
Building and enabling a python virtual environment, etc. (venv)
Build a python virtual environment with virtualenv and virtualenvwrapper
Double-click to open ipynb file (Mac, Anaconda virtual environment)
python package dependencies and virtual environment management tool Poetry
Python Note: The mystery of assigning a variable to a variable
How to build Anaconda virtual environment used in Azure Machine Learning and link with Jupyter
Raspberry Pi + python + IoT device, environment construction procedure to start image processing and machine learning
How to start the PC at a fixed time every morning and execute the python program
python virtual environment Pipenv
virtual environment in python
Note to daemonize python
Connect python to mysql
Virtual environment with Python 3.6
How to build a new python virtual environment on Ubuntu
Enable the virtualenv Python virtual environment for Visual Studio Code
How to connect to various DBs from Python (PEP 249) and SQLAlchemy
A note on how to load a virtual environment in PyCharm
[Python] Building a virtual python environment for the pyramid tutorial (summary)
How to develop in a virtual environment of Python [Memo]
Connect to the Bitcoin network using pycoin (Python Cryptocoin Utili)
After enabling the python virtual environment in the batch file, run the python file
The websocket of toio (nodejs) and python / websocket do not connect.
I want to know the features of Python and pip
How to get into the python development environment with Vagrant
I tried to enumerate the differences between java and python
Building a Python development environment on Windows -From installing Anaconda to linking Atom and Jupyter Notebook-
When you want to use multiple versions of the same Python library (virtual environment using venv)
I tried to find out the difference between A + = B and A = A + B in Python, so make a note
Memo to switch between python2 series and 3 series in anaconda environment of mac (win is also added)