Build a python development environment in linux, linuxpython

Source: Internet
Author: User
Tags install django postgres createdb virtual environment virtualenv

Build a python development environment in linux, linuxpython

Http://blog.csdn.net/pipisorry/article/details/39854707

Build a python development environment in ubuntu 12.04

I. systems and software used

Ubuntu 12.04
Python 2.7.3
Django 1.4.2
Pycharm 2.6.3
Postgresql 9.1
Virtualenv
Virtualenvwrapper
Openjdk

Before you start, you can back up the system. If Postgresql is installed by mistake, you have to reinstall the system after a major problem occurs.

1. Install python
The Ubuntu system comes with python 2.7, which can be used directly. (Because Django 1.4 is used and Python 3.0 or later versions cannot be used, you do not need to reinstall Python)

Pipi @ ubuntu :~ $ Python -- version
Python 2.7.3
2. Install JDK
Because pycharm (python IDE) is written in Java, JDK must be installed before it can run. Skip this step if JDK has been installed before.

Run java-version on the terminal before installation.

Pipi @ ubuntu :~ $ Java -- version
The 'java' program is included in the following software packages:
* Default-jre
* Gcj-4.6-jre-headless
* Openjdk-6-jre-headless
* Gcj-4.5-jre-headless
* Openjdk-7-jre-headless
Please try: sudo apt-get install <selected software package>

Indicates that the system does not have any jdk software.

If it is already installed, delete the earlier version. The command line is as follows:
Sudo apt-get purge openjdk *
If the installed JDK is from another PPA, perform the following steps to install the new JDK:
Sudo rm/var/lib/dpkg/info/The oracle-java7-installer *

Sudo apt-get purge Co., oracle-java7-installer *
Sudo rm/etc/apt/sources. list. d/* java *
Sudo apt-get update


LastStart installing Oracle Java 7

Installing JDK on Ubuntu 12.04 LTS is not complicated, but the latest version of Ubuntu does not support installation through apt-get. Therefore, you need to download the installation package from the official Oracle website for installation.

Root @ ubuntu:/opt # wget http://download.oracle.com/otn-pub/java/jdk/8u20-b26/jdk-8u20-linux-x64.tar.gz

After

[Install JDK in Ubuntu 12.04 LTS]


Sudo add-apt-repository ppa: webupd8team/javasudo apt-get update
Sudo apt-get install oracle-java7-installer
Then the installation is complete.

Apt-get programs are separated, and executable files are generally stored in/usr/bin.
Input echo $ PATH in the terminal to check the PATH. Is there a/usr/bin option? Where is the jdk executable file?
You can try to enter which 'javac' to display the javac path.
/Usr/bin/javac
Only executable files are under/usr/bin. This should be the case.


/*************************************** **************************************** **************************************** **************************************** **********************

If you do not select the virtualenv environment, you can ignore the content not in the * Number of the python project under the virtual environment.

3. Install Virtualenv and Virtualenvwrapper
Virtualenv is installed to build an independent python development environment. In this way, multiple environments with different requirements can be created on one machine. You can create environments with different versions of programs.

For example, you can build a Django 1.4 environment or a Django 1.3 environment. The two environments do not affect each other. In addition, because system-level packages can be used, the entire system will not be confused due to small issues.

Virtualenv installation is simplePip install virtualenv
After the installation, create a virtual environment and install virtualenvwrapper
Virtualenv ENV# ENV is the environment name and can be set as needed. It is actually a folder, which can be found under the username folder in home.
Source ENV/bin/activate# Enter the virtual development environment of virtualenv.

After entering the virtual environment, the command line will be displayed at the beginning (ENV), which indicates that the environment is already in, And then virtualenvwrapper and Django can be installed.
Enter the command linePip install virtualenvwrapper
Sudo is not needed here, because in virtualenv, It is very convenient to manage permissions.

4. Install Django

As long as it is still in the virtualenv environment, the steps for installing Django are exactly the same as those for installing Django. Refer to the steps on the official website. It is actually about downloading and then entering the command line.
Https://docs.djangopRoject.com/en/1.4/toPics/install/# instalLing-a-distribution-Specific-package
1. Download the latest release from our download page.
2. untar the downloaded file (e.g. tar xzvf Django-X.Y.tar.gz, where X.Y is the version number of the latest release ). if you're using Windows, you can download the command-line tool bsdtar to do this, or you can use a GUI-based tool such as 7-zip.
3. Change into the directory created in step 2 (e.g. cd Django-X.Y ).
4. if you're using Linux, Mac OS X or some other flavor of Unix, enter the command sudo python setup. py install at the shell prompt. if you're using Windows, start a command shell with administrator privileges and run the commandpython setup. py install. this will install Django in your Python installation's site-packages directory.

After installing Django, run the deactivate command to exit virtualenv.


5. Install Postgresql
Because Ubuntu 12.10 comes with Postgresql 9.1, you don't need to download it. You can directly enter the command line in terminal to install it.
The command line is as follows:
Sudo apt-get install postgresql-9.1
Install the necessary package and attach the official website introduction and website. Some Packages may have been installed before, but for the sake of security, follow the official instructions to install them.
Http://www.postgresqL.org/download/linux/Ubuntu/
* Postgresql-client-9.1-client libraries and client binaries
* Postgresql-9.1-core database server
* Postgresql-contrib-9.1-additional supplied modules
* Libpq-dev-libraries and headers for C language frontend development
* Postgresql-server-dev-9.1-libraries and headers for C language backend development
* Pgadmin3-pgAdmin III graphical administration utility

Just replace the postgresql-9.1 in the command line with the name of the bread. For example, if you need to install the postgresql-client-9.1, enter
Sudo apt-get install postgresql-client-9.1
The following are all the same.
After installing postgresql, you need to set the database, such as adding a role and creating a database. The specific method is as follows:
Set postgresql users and passwords
Sudo-u postgres createuser
Then follow the prompts to add a user
The first prompt is to enter the user name, and then ask if this user is a Super User, whether it is allowed to create a database, or whether it is allowed to add a new user. You can create a user as needed.
Create a database
Sudo-u postgres createdb mydb# Mydb is the database name and can be set as needed
After the creation, use the psql command to set the password of the user you just created and grant the user the permission to access the database.
Sudo-u postgres psqlpostgres = # alter user linuxpoison with encrypted password 'Password ';
ALTER ROLE
Postgres = # grant all privileges on database linuxdb to linuxpoison;
GRANT
Then, you can use \ l to view the database that has been successfully created, the newly added user, and the database with the access permission.


6. Install psycopg2

You need to re-enter the virtualenv environment.
Source ENV/bin/activate
Then, in the virtual environment, enter
Pip install psycopg2
The installation is complete.
When you need to use data, for example, add import psycopg2 in settings. py of Django. Add postgresql_psycopg2 at the end of the database engine.

**************************************** **************************************** **************************************** **************************************** *********************/

7. Install pycharm

Pycharm can be used as long as it is downloaded. However, in Ubuntu, run pycharm. sh in the bin folder to run Pycharm.
Without special settings, pycharm uses the Python environment of the system by default.

Use the virtualenv we just created as the development environment.

Therefore, we need to further set up to enable Pycharm to use the virtual environment. The official method is as follows:
Http://www.jetbrains. Com/pycharm/webhelp/Creating-virtual-enVironment.html
1. Open the project settings, and click Python Interpreters page.
2. Click in the toolbar.
Create New Virtual Environment dialog box opens.
3. In the Create New Virtual Environment dialog box:
* In the Name field, type the name of the new virtual environment, or accept the suggested default name.
* In the Location field, specify the target directory, where the new virtual environment will be created.
* From Base interpreter drop-down list, select one of the configured Python interpreters, which will be used as the base for the new virtual environment.
* If you want the site-packages of the base interpreter to be visible from the virtual environment, select the check box Inherit global site-packages. if you leave this check box cleared, the new virtual environment will be completely isolated.
* 2.6 + If you want to assign the new virtual environment to be the project interpreter, make sure that the corresponding check box is selected. also, you can make this virtual environment available to all projects, same as when an existing virtual environment is added.
So far, pycharm's Development Environment on ubuntu is complete. You only need to select the virtualenv environment when creating a new project to develop a python project in the virtual environment.



From: http://blog.csdn.net/pipisorry/article/details/39854707

Ref:

Build a python development environment in ubuntu

Build an apache + python runtime environment in ubuntu 12.04 in 3 minutes

Build a Python Development Environment on Ubuntu

Build Python Development Environment pydev in Ubuntu




Build a Python development environment in Windows 7

Pydev + eclipse
All versions are supported.
2.7.X
3.1
3.2

Problems in Linux and python Development

I do not agree with the upstairs comments on the opening of python in linux,
Python can be deployed in windows. You can use python to deploy more applications in linux.

First, python is installed by default in popular linux distributions,
In addition, many software management programs of linux releases are developed using python,
Lz can be seen that the development of python in linux is not big. Basically, Many of python development is about linux.
It is useful to write some scripts.

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.