Posts

Showing posts with the label pycharm

How to create a Unity icon for Pycharm

Image
As every aplications, you can create a .desktop file to run it from your Desktop. If you copy this .desktop file in ~/.local/share/applications, you can see it in Unity, but when you run Pycharm the icon that appears doesn't load. To create an icon here, just open Pycharm and create it clicking on Tools > Create Desktop Entry... Now, you could load Pycharm with an Unity icon. Enjoy it!

How to run root python scripts on Pycharm

Image
Mininet needs root privileges ti run. If you run a python mininet script on Pycharm you will see the following message: *** Mininet must run as root. To enable root privileges, you need create a new interpreter as follows: sudo visudo -f /etc/sudoers.d/python Add the following information: <user> <host> = (root) NOPASSWD: <full path to python> For example: boettcher boettcher-server = (root) NOPASSWD: /usr/bin/python Create a script called python-sudo.sh, containing (with your correct full python path): #!/bin/bash sudo /usr/bin/python "$@" Be sure to make the script executable: chmod +x python-sudo.sh To change your actual interpreter for this new one, in PyCharm, go to File > Settings > Project Interpreter. Click the gear icon by the current Project Interpreter drop-down, and choose “More…”. Then click the green plus icon to add a new interpreter (Add Local). Browse to python-sudo.sh and select it  and ...

How to comment multiple lines in Pycharm

Image
If you have a latin keyboard without numpad or any without slash key, maybe you couldn't use the shortcut enabled in Pycharm to comment multiple lines (Ctrl+Slash). To change this shortcut, you must create a default keymap copy to edit it, just clicking on Copy button. Go to File/Settings... and write keymap Now, filter by comment and add a new keystroke, like Shift+3 Enjoy it!

Debug SDN Ryu controller with Pycharm

Image
If you want debug your Ryu App, you need execute ryu-manager throught Pycharm. To do it, you need execute the following python script in the same folder where you have the ryu app. I got the script from  https://www.mail-archive.com/ryu-devel%40lists.sourceforge.net/msg08519.html #!/usr/bin/env python # -*- coding: utf-8 -*- import sys from ryu.cmd import manager def main(): sys.argv.append('--ofp-tcp-listen-port') sys.argv.append('6633') sys.argv.append('simple_switch_13') sys.argv.append('--verbose') sys.argv.append('--enable-debugger') manager.main() if __name__ == '__main__': main() Where simple_switch_13 is your ryu.app.name. Run with Shift+F9 in Pycharm. If you choose any line in your Ryu app to debug, the console will show you the data about this variable like the following screenshot:

TERM environment variable not set on Python

Image
To avoid this warning when you try clear your console through os.system('clear') on linux, you must configure TERM variable on your environment with "xterm-color" value. In Pycharm, you can add it on File/Settings.../Build, Execution, Deployment/ Console/Python Console Enjoy it!

How to enable Sphinx documentation in Pycharm

Image
Sphinx is a tool that makes it easy to create documentation. It was originally created for the new Python documentation, and enables to create it on html, LaTeX or linkcheck. See this blog for more information about Shpinx First, you need install Shpinx it on your system: pip install Sphinx Now, you need configurate the project folder from Pycharm on Tools/Sphinx Quickstart You should get this error: ReStructuredText Error  No sdk specified To solve it, use the same solution that in this previous post Now, you can compile your code to generate a html or a LaTeX file. Go to your project folder on your terminal and write: #if you want html make html #if you want LaTeX make latex If you want generate this from Pycharm, you need create an external tool. Go to  File/Settings.../Tools/External Tools/  and add the following configuration: Go to  Tools/External Tools/Generate HTML and you will see the following ...

Error: Cannot start process, the working directory does not exist

Image
I got this error on Pycharm Python Console. It's an error running console. To solve it, just remove .idea folder in your project and re run Pycharm. Enjoy it!

How to write a file code template in Pycharm

Image
To add utf-8 compatibility in all your scripts, one solution is enable a template that add this compatibility and other information as copyright, your name, etc. File and code templates are written in the Velocity Template Language (VTL). So you may include variables as ${YEAR}, ${USER}, etc. To add code to your scritps go to File/Settings.../Editor/File and Code Templates Select Python Script and add the following lines: #!/usr/bin/env python2 # -*- coding: utf-8 -*- # Copyright (C) ${YEAR} ${USER} Now, if you create a new Python file, it will generate with this header code by default. If you want more VTL variables please go  here Enjoy it!

How to configure Pycharm with github

Image
If you configured a previous project with your github account and now you try to work on it with Pycharm, yu will see this message when you'll start this IDE: Unregistered VCS root detected The directory ... is under Git, but is not registered in the Settings. Add root  Configure  Ignore Press Add root to add your folder to the git project configured on it. Go to the Version Control tab and start to add files to it with Add to VCS (or press Ctrl + Alt + A on the file) on the ChangeList catalogued as Unversioned Files.    When you are done, click on Commit Changes Now, write your Commit Message and push the Commit button and choose Commit and Push Write your github user and password and you are done. Enjoy it!

Enable Python interactive console in PyCharm

Image
Python has an interactive console that enable to explore your code after executing the script or the   command. If you run your code without interactive option you will see this message: Process finished with exit code 0 To activate it, go to Run/Edit Configurations ... remove all configurations (to the right of plus green icon) and write -i on interpreter options from Defaults/Python . Also, you can enable  Show command line afterwards checkbox, but your script may crash with this  following error, when try to read a string from the keyboard. Exception in thread ServerThread (most likely raised during interpreter shutdown): Process finished with exit code 1 Enjoy it!

Install PyCharm Community Edition 2016.2.3 on Ubuntu with IPython/Jupyter Notebook compatibility

Image
PyCharm is another IDE for Python (in my last post I see how to install Spyder ) It has the advantage that you have multiples modes of view.  My favourite is the presentation Mode, perfect when you have a presentation and you need magnify the fonts and you need to show a on-demand code execution. Also, you can install jupyter to run ipython notebook inside the IDE.  To install PyCharm follow these commands: wget https://download-cf.jetbrains.com/python/pycharm-community-2016.2.3.tar.gz tar xvf pycharm-community-2016.2.3.tar.gz cd pycharm-community-2016.2.3/bin ./pycharm.sh Now, to install ipython and jupyter, follow these commands: sudo apt-get install ipython-notebook sudo pip install jupyter Run PyCharm and now create a new project. Now, create a new Jupyter Notebook with an ".ipynb" extension (IPYthon NoteBook): In the first cell puts: %matplotlib inline This sentence enable to display figures on th...