It seems to be possible to use Python script with NLTK package in C# on Azure website.
I tried to implement it via a workaround way as below, and it works fine.
Step 1. For installing Python & NLTK on Azure WebApp
- Access the Kudu tool of your webapp via the url
https://<your webapp name>.scm.azurewebsites.net
.
- Install a site extension
Python 2.7.12 x86
which will be installed at the path D:home
if using the 32bit version of Azure WebApp as example.
- Switch to the Kudu CMD, then you can see a new Python runtime which has been installed at here and you have permission to do any operations on it.
- Commands
cd Python27
and touch get-pip.py
and copy the content of the url https://bootstrap.pypa.io/get-pip.py
into the get-pip.py
via Edit
button, then run python get-pip.py
to install the pip
tool.
- Command
Scriptspip install nltk
to install nltk
package.
- To download the nltk data, command
python -m nltk.downloader -d D:homePython27
ltk_data all
as below, please don't close the current browser window or switch other urls until the command completed
You can view the download task in process as below via the url https://<your webapp name>.scm.azurewebsites.net/ProcessExplorer/
at the other browser window.
6.1 Or you can download the nltk data on local to upload them into Azure WebApp.
Step 2. For testing Python script with NLTK package
Command touch test.py
at the path wwwroot
, and edit the content below.
import nltk
sentence = """At eight o'clock on Thursday morning
... Arthur didn't feel very good."""
tokens = nltk.word_tokenize(sentence)
print tokens
The console show the result as below, it works.
Step 3. Calls python script via Process
in C#
Just only using the absoulte path of python runtime & script D:homePython27python
& D:homesitewwwrootest.python
instead of them in your C# code.
Please try and feedback your result. Any concern, please feel free to let me know.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…