zoukankan      html  css  js  c++  java
  • eclipse安装pydev插件

    pydev是eclipse开发python的差距。
       强大的调试功能和舒服的编辑环境让pydev赢得了许多人的青睐。不过eclipse本来就是耗资源大户,pydev在这一点上毫无办法,但现在的电脑都很快了,跑eclipse根本就是小case,不用担心太多。除了强大的调试功能,依靠 eclipse,pydev的代码浏览能力是其它所有IDE所不能比的,比如按住CTRL键再点击一个类就能自动跳到该类的定义,这对于阅读代码非常有用。现在pydev extension也开源了,所以一些(我不知道的)高级的功能也被融入到pydev里了。推荐度★★★★★
    下载:http://pydev.org/download.html
    注意pydev可以在eclipse里在线安装,请阅读上面那个网页的右边的Quick Install.

    (python其他的ide参考:http://www.cnblogs.com/wongsimin/articles/1936415.html)

    去官网下载后解压放到Plugings目录下

    cmd里eclipse -clean 重启。

    如果正确安装,打开菜单 'window > preferences',你可以看见多了一个PyDev项。

    接下来我们要配置解释器.config interpreter

    Configure Interpreter

    After installing it, the first thing you must do is configure the Python and/or Jython and/or IronPython interpreter. 
    To configure the interpreter:

    1. Go to: window > preferences > PyDev > Interpreter - (Python/Jython/IronPython).

    2. Choose the interpreter you have installed in your computer (such as python.exe, jython.jar or ipy.exe).

    Note that the Auto Config will try to find it in your PATH, but it can fail if it's not there (or if you
    want to configure a different interpreter).

    On Windows it'll also search the registry and provide a choice based on the multiple interpreters available
    in your computer (searching in the registry).

    ................

    我电脑上面安装的是标准python,选择interpreter-python,选择解释器路径:E:/program files/python2.7/python.exe.

    3. Select the paths that will be in your SYSTEM PYTHONPATH.

    IMPORTANT: Select only folders that will NOT be used as source folders for any project of yours 
    (those should be later configured as source folders in the project).

    pytdev会自动列出 lib路径和site-packages,点击ok,就可以自动配置信息了。

    配置完成后,就可以使用了。

    详细参考:http://pydev.org/manual_101_interpreter.html

    创建工程:

    http://pydev.org/manual_101_project_conf.html

    Eclipse:

    file > new > project > PyDev > PyDev project. You should see the screen below:

    Create default 'src' folder and add it to the pythonpath: If you don't leave that option checked, you'll have to create
    the source folder(s) yourself after the project is created (which is covered in the next tutorial page).

    You may finish in this screen or go to the next, where you will be asked which projects are referenced from this one.

    我安装的版本与上面的稍有不同:

    遇到一个错误:

    1. .project found in C:\workspace(use import project)

    But I have no project called that in my workspace. I have tried with a lot of names for my project, but always the error message. I can't make a new project.

    原因是在所选择的的文件夹下有.project这个文件(隐藏的)我们需要更换另一个目录。

    http://loosky.net/archives/1152.html

    创建好的:

    pydevTest项目

    创建新的Pydev Module
    光有项目是无法执行的,接着必须创建新的Pydev Moudle,选择File -> New -> Pydev Module

    在弹出的窗口中选择文件存放位置以及Moudle Name,注意Name不用加.py,它会自动帮助我们添加。然后点击Finish完成创建。

    输入代码:

     

    执行程序
    程序写完后,我们可以开始执行程序,在上方的工具栏上面找到执行的按钮。

    之后会弹出一个让你选择执行方式的窗口,通常我们选择Python Run,开始执行程序。

    一直认为pydev不能像Idle那样有交互式shell。所以我也一直没有用它,确实,交互式shell太重要了了。后来发现pydev是支持交互式shell的。

    官方文档:

    http://pydev.org/manual_adv_interactive_console.html

    按Ctr+alt+enter会自动执行当前文件,显示交互式shell,如:

    》》》execfile('F:\\pythonSource\\src\\Test1.py')(系统默认执行当前所编辑的文件
    》》》hello world
    》》》a=MyClass()
    》》》a.func()
    Out[1]: 'hello world'

    pydev console其他特征:

    • Up / Down Arrows cycles through the history (and uses the current text to match for the start of the history command) up/down显示前后命令
    • Esc: clears current line
    • Paste added directly to the command line
    • Cut will only cut from the command line
    • Copy does not get the prompt chars
    • Home goes to: first text char / prompt end / line start (and cycles again)
    • Cursor automatically moved to command line on key events 在pydev任何位置输入 字符都会自动跳到输入位置
    • Multiple views of the same console can be created
    • Limitation: Output is not asynchonous (stdout and stderr are only shown after a new command is sent to the console)

    pydev debug参看:

    http://pydev.org/manual_adv_debug_console.html

    pydev交互式模式对中文文件支持很不好,我发现对中文文件名和中文目录都不能正确解析:如:

    execfile('F:\\pythonSource\\爬虫\\Post传参.py')
    Traceback (most recent call last):
    File "E:\ProgramFiles\pythonxy\python27\lib\site-packages\IPython\core\interactiveshell.py", line 2745, in run_code
    exec code_obj in self.user_global_ns, self.user_ns
    File "<ipython-input-1-8b6d506ed4db>", line 1, in <module>
    execfile('F:\\pythonSource\\爬虫\\Post传参.py')
    IOError: [Errno 2] No such file or directory: 'F:\\pythonSource\\\xe7\x88\xac\xe8\x99\xab\\Post\xe4\xbc\xa0\xe5\x8f\x82.py'

    现在不知道怎么解决

    解决不能输出中文问题:

    这是python老生长谈的问题了,解决办法:

    window--Preferences--Pydev--Editor--Template--Empty 这个就是pydev module的模板文件,点击编辑:可以把原来的模板文件里的内容删掉(不删也可以)。添加
    #coding=gbk

    即可。

    另外办法;http://blog.sina.com.cn/s/blog_779eecd801011j7x.html

     把编码设置为utf-8。

    加上

    import sys
    reload(sys)
    sys.setdefaultencoding('utf-8');

    在eclipse中我编写如下的代码:

    #coding=utf-8
    
    s='中文'
    print s

    可以输出中文,可是每次运行后源代码中的中文就会变成乱码,不止为什么。原来是Eclipse默认页面文件编码为gbk,

    改为utf-8就一切正常了。运行能正确输出中文,页面也不乱码,应该是最好的一种解决方案。

    Window->Preferences->General->Workspace->Text file encoding

    将其改为UFT-8即可。

    但是这种修改只对当前的workspace有效,如果新建或者切换到一个新的workspace下,还是得做同样的步骤。

    同样

    Window->Preferences->General->Content Types中可以修改具体的不同格式的文件的默认编码,尤其是HTML,CSS,Javascript等文件的编码最好是修改一下,否则默认的ISO- 8859-1无法支持中文。

    不知道如何解决默认安装完是GBK的问题,难道一定要用英文操作系统?

    myeclipse6.0下怎么样统一全部文件编码:

    windows---->preferences---->myeclipse---->file and editors----->jsp--->把这个目录下的encoding选为你要设置的编码(如UTF-8) 
    这样,你下次再新建一个JSP页面的时候就默认是以你刚才设置的编码了 
    因为默认情况下新建一个JSP页面的编码是ISO8859-1的,是不能存中文的,要存中文就得手动改为GBK,UTF-8支持中文的编码,每次新建都要修改手动修改一次编码就很麻烦. 
    经过上面的设置后就可以统一整个项目的编码而不用再手动设置.

     对于eclipse,单独设置某类文件编码:

    window-》preference-》appearance-》contents types,选择文件类型

    如java,点击Text展开,就可以看到java了,设置编码。

    pydev修改字体。

    pydev字体默认为10号。其实pydev没有字体设置选项,字体是Eclipse设置的。在

    window-->preference-->General-->Appearance-->Colors and Fonts

    设置为Courier new 12即可。

    记住我们设置的是Basic的text font,不是java的text font。eclipse对各个不同工程的字体可单独设置

     pydev更多使用技巧:

    http://www.ibm.com/developerworks/cn/opensource/os-cn-ecl-pydev/

  • 相关阅读:
    为什么Java中 wait 方法需要在 synchronized 的方法中调用?
    XML常用解析API有哪几种?
    Dubbo 和 Spring Cloud 的区别?
    Java 线程池中 submit() 和 execute()方法有什么区别?
    详细描述一下 Elasticsearch 搜索的过程?
    为表中得字段选择合适得数据类型 ?
    Json有什么作用?
    Ajax的乱码解决问题?
    eclipse安装配置记录
    srs部署/webrtc拉流
  • 原文地址:https://www.cnblogs.com/youxin/p/3061978.html
Copyright © 2011-2022 走看看