Sunday, August 14, 2016

PyDev in Eclipse Cannot Locate multiprocessing.Process

I am using PyDev with Eclipse. Recently, I found that PyDev complains that it cannot find multiprocessing.Process when it analyzes the code, as such, it marked "Process" as a symbol that cannot be resolved in a statement as below, although I can run and debug the script without any problems,


    from multiprocessing import Process


A discussion at Stackoverflow comes to rescue and provides the following answer,


"If you're using Eclipse and PyDev you need to include 'multiprocessing' as a forced builtin for the python interpreter."

The question becomes, how may we add a forced builtin? The answer is in this PyDev manual page, that is,
  1. Go to: window > preferences > PyDev > Interpreter - (Python/Jython/IronPython).
  2. Choose the interpreter you have installed in your computer.
  3. Select "Forced Buildins", and choose "New", finally, add "multiprocessing".



Sunday, August 7, 2016

Developing Google Apps Scripts Add-ons

This posts provides a brief review on the advanced techniques to develop, manage revisions, and publish Google Apps Scripts add-ons.

It is assumed that you have installed the node-google-apps-script that provides gapps and authenticated it with Google Apps engine, and uses Eclipse to manage the Google Apps Scripts add-ons projects.

Initiating a Project

  • Create a new Google Apps Script project remotely at http://script.google.com, name the project properly, and allow it to save to the Google Drive. Note that the project will be stored in your Google drive. You should also now look up the the project id, which can be accomplished by at http://script.google.com, going to "File", and then "Project properties", finally, locating the "Script ID".
  • Create a JavaScript project locally using Eclipse or some other IDEs of your choice.
  • Initialize  the project with gapps locally as follows,
    
    gapps init my_project_id
    

    Note that my_project_id must be replaced by the actual project id.

Developing and Revision Management

You can now develop the project locally and manage it using any revision management system you prefer, such as git.

Be aware that locally, the main script is named as Code.js instead of Code.gs. It will be automatically named as Code.gs when it is uploaded to your Google drive.

Uploading Project


Having tested your code, you can now upload our project to the Google Drive.

gapps upload

Publishing Project

To publish the Google Scripts Add-on projects to the Google Chrome Web Store, you must first have a verified Google Chrome Web Store Console account, without which, you will not be able to publish your project and at present, the website http://script.google.com does not give you much meaningful error messages either.

Therefore, you must first verify your account at Google Chrome Web Store Console site, for which, Google requires you to pay a nominal fee, at  the time this post is written, $5.

Once you meet the above requirement, to publish an add-on, or to update an published add-on. Detail information is in this piece of Google documentation. In the nutshell, at http://script.google.com, choose "Publish", and then select "Publish as Web Add-on".





Friday, August 5, 2016

Installing Adobe Reader in Ubuntu 16.04 LTS

For those who like Adobe Reader to read PDF files, you may find it difficult to install Adobe Reader on Ubuntu 16.04 LTS systems. Assembling information from a few posts, here is the solution that worked for me,
 

sudo apt-get clean all
sudo add-apt-repository "deb http://archive.canonical.com/ precise partner"
sudo apt-get update
sudo apt-get install adobereader-enu
sudo add-apt-repository -r "deb http://archive.canonical.com/ precise partner"
sudo apt-get clean all
sudo apt-get update

If you are on a x64 system, you may see many annoying warning messages when you run acroreader, such as,

......
(acroread:19366): Gtk-WARNING **: Unable to locate theme engine in module_path: "murrine",
......
Gtk-Message: Failed to load module "canberra-gtk-module"
Gtk-Message: Failed to load module "gail"
Gtk-Message: Failed to load module "atk-bridge"


To get rid of the warning messages, install these four packages gtk2-engines-murrine, libcanberra-gtk-module, libatk-adaptor, and libgail-commonfor i386 as follows,

sudo apt-get install gtk2-engines-murrine:i386 libcanberra-gtk-module:i386 libatk-adaptor:i386 libgail-common:i386

If you are running Gnome like I do, then the last step is to set up default application for open PDF files. This is to edit the /etc/gnome/defaults.list file.

sudo gedit /etc/gnome/defaults.list
The editing is to find and replace the line

application/pdf=evince.desktop

by

application/pdf=acroread.desktop
and add the following lines to the end of the file,

application/fdf=acroread.desktop
application/xdp=acroread.desktop
application/xfdf=acroread.desktop
application/pdx=acroread.desktop

Finally, run nautilus to apply change if you do not wish to log out and log back in.

nautilus -q


Saturday, July 23, 2016

Managing Python Environment using Anaconda

Previously, we discussed that you could manage multiple versions of Python runtime environment on Linux systems using python-virtualenv. This post is a note on how we may manage Python runtime environment using Anaconda. Anaconda is a cross-platform tool, and runs on Windows, Mac OS X, and Linux.

Below are steps tested on a Windows 10 system.
  1. Download Anaconda package and install it.
  2. You can now see that Python is installed
    
    C:\Users\DemoUser>python --version
    Python 3.5.2 :: Anaconda 4.1.1 (64-bit)

  3. See this page for how to manage different version of Python environment. Below shows how we may bring Python up-to-date.
    
    C:\Users\DemoUser>conda update python
    Fetching package metadata .......
    # All requested packages already installed.
    # packages in environment at C:\Anaconda3:
    # python 3.5.2
    

Of course, we can do more with Anaconda, such as, manage Python packages. Below shows that we can install Gensim and all its dependencies in one single step.


C:\Users\DemoUser>conda install -y gensim
Fetching package metadata .......
Solving package specifications: ..........

Package plan for installation in environment C:\Anaconda3:

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    bz2file-0.98               |           py35_0           6 KB
    conda-env-2.5.2            |           py35_0          67 KB
    conda-4.1.9                |           py35_0         247 KB
    smart_open-1.3.3           |           py35_0          28 KB
    gensim-0.12.4              |      np111py35_0         2.2 MB
    ------------------------------------------------------------
                                           Total:         2.6 MB

The following NEW packages will be INSTALLED:

    bz2file:    0.98-py35_0
    gensim:     0.12.4-np111py35_0
    smart_open: 1.3.3-py35_0

The following packages will be UPDATED:

    conda:      4.1.6-py35_0       --> 4.1.9-py35_0
    conda-env:  2.5.1-py35_0       --> 2.5.2-py35_0

Fetching packages ...
bz2file-0.98-p 100% |###############################| Time: 0:00:00  95.70 kB/s
conda-env-2.5. 100% |###############################| Time: 0:00:00 245.29 kB/s
conda-4.1.9-py 100% |###############################| Time: 0:00:01 155.70 kB/s
smart_open-1.3 100% |###############################| Time: 0:00:00 205.54 kB/s
gensim-0.12.4- 100% |###############################| Time: 0:00:15 150.04 kB/s
Extracting packages ...
[      COMPLETE      ]|##################################################| 100%
Unlinking packages ...
[      COMPLETE      ]|##################################################| 100%
Linking packages ...
[      COMPLETE      ]|##################################################| 100%
C:\Users\DemoUser>


Note that in the above we install packages for DemoUser. To install packages system-wide, we need to be elevated to system administrator.

Wednesday, July 20, 2016

Plagiarism Checking Tools

As the title suggests, here is a list of plagiarism checking tools, some of which offer free services,

Saturday, July 9, 2016

Running Multiple Versions of Python on a Single Linux System

While some Python applications are written in Python 3, some others are still being maintained and developed in Python 2. That is to say, there is a need to run multiple versions of Python on a single system. The following steps show that you can install multiple versions of Python on a single Linux system, and activate and deactivate the version you wish to use conveniently by leveraging on virtual python environments. Note that the following steps are tested on a Debian-based Linux system, such as Debian Linux and Ubuntu Linux

  1. Install the Python 2 and Python 3 if you have not done so.
    
    sudo apt-get install python python3
    

  2. Install python-virtualenv packages. This step is the key.
    
    sudo apt-get install python-virtualenv
    

  3. Show that you have both python 2 and 3 binaries. In the Linux system I am using for this post, the python binary by default points to Python 2's binary. Yours may differ.
    
    $ python --version
    Python 2.7.6
    
    $ python3 --version
    Python 3.4.3
    

  4. To develop or run some applications in python 3, we need to activate Python 3. Then, first create a directory as the working directory for the Python 3 application. For instance, we name the directory as proj_python_3.
    
    $ mkdir proj_python_3
    

  5. Now switch to the directory.
    
    cd proj_python_3
    
    $ which python3
    /usr/bin/python3
    

  6. Then activate Python 3, we first need to set up an environment in the working directory for Python 3.
    
    $ virtualenv -p /usr/bin/python3 .env
    Running virtualenv with interpreter /usr/bin/python3
    Using base prefix '/usr'
    New python executable in .env/bin/python3
    Also creating executable in .env/bin/python
    Installing setuptools, pip...done.
    

  7. Now we can activate Python 3 any time we wish after we switch to the working directory.
    
    $ pwd
    /home/user/proj_python_3
    
    $ . .env/bin/activate
    (.env)$
    

    Note that the prompt shows that you are under a virtual environment for Python 3. You can show that the activated Python version is Python 3.
    
    (.env)$ python --version
    Python 3.4.3
    

  8. To deactivate the virtual environment, run the following,
    
    
    (.env)$ deactivate
    $ python --version
    Python 2.7.6
    

At present, the working directory for the virtual python environment must be on a file system that supports symbolic links; otherwise step 6 will fail.

Monday, March 14, 2016

Diagnosing Windows File and Printer Share

When we find that the Windows File and Printer Share does not work as we desire, e.g., you may observe an error as follows,

System error 53 has occurred.

The network path was not found.

many factors can contribute to the problem, commonly,
  • Name resolution including both Domain Name Resolution (DNS) and NetBIOS Name Resolution
  • Windows Firewall
I find that it is efficient to follow the steps below to diagnose the problems, where we assume that a resource, "MYSHARE" is shared on a remote host with DNS name "MYHOST.MYDOMAIN.COM", NetBIOS name "MYHOST", and IP address "192.168.1.102"
  1. Disable Windows Firewall on the remote host
  2. Check any of special hidden administrative shares is accessible on the client host using the remote host's IP address, e.g.,
    
    net use \\192.168.1.101\Admin$

    If the resource is accessible, you will be prompted for username or password, e.g.,
    
    C:\>net use \\192.168.1.102\admin$
    The password is invalid for \\192.168.1.102\Admin$.
    
    Enter the user name for '192.168.1.102':
    

  3. If Step 2 fails,it is likely that you have forgotten to share the resource. Follow the Microsoft's guideline to share the resource.
  4. If Step 2 succeeds, check if the remote host's NetBIOS name registered and resolved on the client host,
    
    C:\>nbtstat -a myhost
    

    Depending on the number of interfaces that the client machine has, it may take a while. Regardless, it should show that the NetBIOS Name "myhost" should be registered on the network interface via which the remote machine is accessible, e.g.,
    
    
    Ethernet 3:
    Node IpAddress: [192.168.1.101] Scope Id: []
    
               NetBIOS Remote Machine Name Table
    
           Name               Type         Status
        ---------------------------------------------
        MYHOST         <20>  UNIQUE      Registered
        MYHOST         <00>  UNIQUE      Registered
        WORKGROUP      <00>  GROUP       Registered
        WORKGROUP      <1e>  GROUP       Registered
    
        MAC Address = 66-11-22-33-44-55
    
    
    where we assume the client host's IP address is 192.168.1.101.

  5. If Step 4 fails, you must set up the NetBIOS name properly on the remote host by following Microsoft's guideline. You may also refer to this article on NetBIOS naming.
  6. Then, you can now try to access the shared resource on the remote host using the resource name and the remote host's NetBIOS name. The resource should be in the form of "\\MYHOST\MYSHARE".
    
    net use \\MYHOST\MYSHARE

    Or, if you need to provide a different Windows credential,
    
    net use \\MYHOST\MYSHARE /user:MYHOST\MYUSERNAME

  7. Now enable Windows Firewall and repeat Step 6. If Step 6 is successful, the Windows Firewall has already been configured to allow the Windows File and Printer share. If not, allow the Windows File and Printer Share in the Window Firewall, following the Windows guideline.