Tagged with: MongoDB python virtual Environment MongoDB drive environment
1. Create a Python virtual environment
Python2 and Python3 are already installed in Fedora, and the executable directory is in the/usr/bin/directory, where the soft connection is
python->python2python2->python2.xpython3->python3.x
The next step is to use Python3 to operate MongoDB, so as to not pollute the original system environment, and isolate this particular application, the use of Python virtual environment.
Create a virtual environment
Grammar
$ python3 -m venv /path/to/new/virtual/environment
Example
$ python3 -m venv py3mongodb或者$ python3 -m venv ~/py3mongodb
The directory for the Python virtual environment will be generated when execution is complete, py3mongodb.
Using the specified virtual environment
Grammar
$ source <venv>/bin/activate
Example
$ source py3mongodb/bin/active或者$ source ~/py3mongodb/bin/active
The result of executing the "which python" command at this time is ~py3mongodb/bin/python
The result of executing the "python-v" command at this time is Python 3.x.x
Exiting the current virtual environment
Grammar
$ deactivate
Python's Virtual Environment reference:
Https://docs.python.org/3/tutorial/venv.html
Https://docs.python.org/3/library/venv.html#module-venv
2. Install the MongoDB python driver
Online installation
Recommended PIP Installation
$ python -m pip install pymongo
Upgrade Pymongo
$ python -m pip install --upgrade pymongo
SOURCE Installation
Premise Dependent installation
With C extension dependent
$ sudo yum install gcc python-devel$ git clone git://github.com/mongodb/mongo-python-driver.git pymongo$ cd pymongo/$ python setup.py install
Does not include C extension dependencies
$ python setup.py --no_ext install
For more official details, see the official MongoDB documentation.
Use Python to learn notes on Fedora