Use Python to learn notes on Fedora

Source: Internet
Author: User
Tags mongodb documentation virtual environment

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.