Build a python development environment in Linux

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

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

Setting up a python development environment in Ubuntu 12.04

First, the use of the system and software

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 make a backup of your system. If you mistakenly install PostgreSQL, there is a big problem, you have to put the system to reload.

1. Install Python
The Ubuntu system comes with Python 2.7, which can be used directly. (with Django 1.4, you can't use Python 3.0 or later, so you don't have to reinstall Python)

[Email protected]:~ $python--version
Python 2.7.3
2. Installing the JDK
Because the Pycharm (Python IDE) is written in Java, the JDK must be installed to run. If you have previously installed a JDK, you can skip this step.

before the installation, the terminal executes the java-version

[Email protected]:~ $java--version
The program ' Java ' is already included in the following 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 packages >

Description The system does not have any JDK software

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

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


Finally, start installing Oracle Java 7

Installing the JDK on Ubuntu 12.04 Lts is not complicated by itself, but the newer version of Ubuntu is not supported directly through the Apt-get installation. Therefore, the installation package needs to be downloaded from the official Oracle website.

[Email Protected]:/opt#wget http://download.oracle.com/otn-pub/java/jdk/8u20-b26/jdk-8u20-linux-x64.tar.gz

After

"Ubuntu 12.04 LTS installation JDK"


sudo add-apt-repository ppa:webupd8team/javasudo apt-get update
sudo apt-get install Oracle-java7-installer
After that, the installation is complete.

Apt-get installed program is separate, executable file generally under/usr/bin
Enter the Echo $PATH under terminal to see the path,/usr/bin this one? The JDK executable file is there
You can try the input which ' javac ', which will show the path of Javac
/usr/bin/javac
Only the executable file is below/usr/bin, so it should be.


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

Do not select the VIRTUALENV environment, that is, the content in the * number of the Python project that is not developed in a virtual environment can be ignored

3. Installing virtualenv and Virtualenvwrapper
The virtualenv was installed primarily to create a separate Python development environment. This allows the creation of multiple environments with different requirements on a single machine. You can create an environment with different versions of the program.

For example, you can build a Django 1.4 environment, or you can build a Django 1.3 environment that doesn't affect the environment. And because you can not use system-level packages, the entire system is not cluttered because of small problems.

The installation of the virtualenv is simplepip Install virtualenv
After installation, create a virtual environment, and then install the Virtualenvwrapper
virtualenv ENV#ENV for the environment's name, can be arbitrarily set, in fact, is a folder, under the home under the User name folder can be found.
Source Env/bin/activate#这样进进入了virtualenv的虚拟开发环境.

After entering the virtual environment, the command line will start to show (ENV), the representative has entered the environment, then you can install Virtualenvwrapper and Django
Enter command linepip Install Virtualenvwrapper
It is not possible to use sudo here, because in virtualenv, it is one of the most convenient designs without administrative privileges.

4. Install Django

As long as you're still in the VIRTUALENV environment, the steps to install Django are exactly the same as the steps to actually install Django. You can refer to the steps of the official website. It's actually 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 does this, or you can use a gui-based tool such as 7-zip.
3. Change to 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 She ll prompt. If you ' re using Windows, start a command shell with administrator privileges and run the Commandpython setup.py install. This would install Django in your Python installation ' s site-packages directory.

After installing Django, use the Deactivate command to exit virtualenv.


5. Installing PostgreSQL
Because Ubuntu 12.10 comes with Postgresql 9.1, you don't have to download it, you can install it directly in the terminal by typing the command line.
The command line is as follows:
sudo apt-get install postgresql-9.1
Then install the necessary packages, and attach the website's introduction and website. Some packages may have been installed before, but for the sake of insurance, install one side according to the official introduction.
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 next bread. For example, if you need to install postgresql-client-9.1, enter
sudo apt-get install postgresql-client-9.1
The following are all the same.
After you install PostgreSQL, you need to make some settings for the database, such as adding role, creating a database, and so on. Here's how:
set the user and password for PostgreSQL
sudo-u postgres CreateUser
Then follow the prompts to add the user
The first hint is to enter a user name and then ask if the user is a superuser, is not allowed to create a database, is not allowed to add new users. You can create a user by answering as needed.
Create a database
sudo-u postgres createdb mydb#mydb is the name of the database and can be set as you wish
After creation, use the Psql command to set the password of the user you just created, and give this user permission to access the database
Sudo-u postgres psqlpostgres=# alter user Linuxpoison with encrypted password ' password ';
ALTER ROLE
postgres=# Grant all privileges on the database linuxdb to Linuxpoison;
GRANT
You can then use \l to see the database that has been successfully created and the user who has just been added and has access to the database.


6. Installing PSYCOPG2

Need to re-enter the VIRTUALENV environment just now.
SOURCE Env/bin/activate
Then in the virtual environment, enter
Pip Install PSYCOPG2
The installation will be complete.
When you need to use the data, for example in Django settings.py, add the import psycopg2. Then add postgresql_psycopg2 at the end of the database engine.

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

7. Installing Pycharm

Pycharm actually can be used as long as it is downloaded. However, in the Ubuntu system, you need to run the pycharm.sh in the Bin folder to run Pycharm.
If there is no special setting, Pycharm will use the system's Python environment by default.

Use the virtualenv we have just established as the development environment.

Therefore, further setup is required to allow Pycharm to use the virtual environment. SpecificofficialHere's how:
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 would be created.
* FROM Base interpreter Drop-down list, select one of the configured Python interpreters, which'll be used as the base F or the new virtual environment.
* If you want the site-packages of the base interpreter to is visible from the virtual environment, select the check box I Nherit Global site-packages. If You leave this check box cleared, the new virtual environment would be completely isolated.
* 2.6+ If want to assign the new virtual environment to being the project interpreter, make sure that the corresponding C Heck box is selected. Also, you can make this virtual environment available to all projects, same as if an existing virtual environment is add Ed.
At this point, pycharm on the Ubuntu development environment, even if the building is complete. You can develop a Python project in a virtual environment as long as you select the VIRTUALENV environment when you create a new project.



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

Ref

Build a python development environment under Ubuntu

Ubuntu 12.04 under 3 minutes to build the Apache+python operating environment

Python development environment built on Ubuntu

Build Python development environment under Ubuntu Pydev



Build a python development environment in Linux

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.