"import nltk" - Not working on xampp - apache

I'm new to python and nltk. I have problem on import nltk.
I installed python in xampp on windows under the path C:\xampp\Python.
And I installed nltk under the path C:\xampp\Python.
After this I configured apache and run some sample python code, it worked well on the browser.
The URL is : /localhost/cgi-bin/test.py.
When I import the nltk in test.py its not running. The execution not continue after the "import nltk" line.
But when I run in the command prompt its working perfect.
Please let me know how to fix this issue.
Below is the sample code :
#!C:\Xampp\Python\python
print "Content-type: text/html\n\n"
import nltk
print "<html>"
print "<head>"
print "<title>This is test</title>"
print "</head>"
print "<body>"
print "This is paragraph"
print "</body>"
print "</html>"
I checked in the apache error log it look like below.
[Fri May 17 18:21:28.774308 2013] [cgi:error] [pid 2952:tid 1732] [client] AH01215: ValueError: Could not find a default download directory\r
I'm creating UI for nltk please help me. Thanks.

From looking at the code here, it appears that the library has platform-specific path handling and that error is thrown in the *nix branch. The code to detect Windows looks like this:
if sys.platform == 'win32' and 'APPDATA' in os.environ
I hope that sys.platform isn't getting messed up, so I think it's most likely that Apache isn't propagating the APPDATA environment variable down to your code.
This question explains why that is and gives a workaround.

Related

Import does not function as bat file; but works in spyder

I am still not the most sophisticated python user; but I cannot overcome this probably simple problem. I have a code that works perfectly with the spyder interface. I would like to make it a recurring task via creating a bat file. The bat file which in turn triggers a cmd interface does not import pandas_data reader and the code gets stuck and aborts.
import pandas_datareader.data as web
this line above creates the error below. It's a lengthy text.
File "C:\Users\myself\anaconda3\lib\site-packages\pandas_datareader\__init__.py", line 2, in <module>
from .data import ( File "C:\Users\myself\anaconda3\lib\site-packages\pandas_datareader\data.py", line 9, in <module>
from pandas.util._decorators import deprecate_kwarg File "C:\Users\myself\anaconda3\lib\site-packages\pandas\__init__.py", line 17, in <module>
"Unable to import required dependencies:\n" + "\n".join(missing_dependencies) ImportError: Unable to import required dependencies: numpy:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
1. Check that you expected to use Python3.7 from "C:\Users\myself\anaconda3\python.exe",
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy version "1.17.0" you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.
Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.
Original error was: DLL load failed: The specified module could not be found.

Why I am getting error as "ImportError: No module named pyPdf" even after installing PyPdf3

I am trying to customize a module in Odoo 10. And I have created a addon path for the new module but I have no good right!
I am getting error "ImportError: No module named pyPdf". Since I am beginner on coding industry I find difficult to sort out this issue. Can anyone help me to sort out this issue?
Python3 support was introduced in Odoo 11, IIRC. So just try to install pyPdf for Python2.
This is usually a path problem. You should check that the directory containing pyPDF is on the Python path.
> # Print a list with the directories in the Python path
> import sys
> sys.path
Note: If you are running Odoo under a python virtual environment activate it first.
Try to run using python2
Try this on the terminal,
python2 path_to_odoo_folder/./odoo-bin

How can I configure global settings for default shell for Scrapy

I started to learn Scrapy but I stuck up at weird point where I couldn't set default shell to ipython. The operating system of my laptop is Ubuntu 15.10. I also installed ipython and scrapy. They run well without causing any errors.
According to Scrapy's official tutorial, I can change my default scrapy shell by entering this in the global configuration file
[settings]
shell = ipython
The problem is I couldn't locate the configuration file. I tried following instructions from another page.
I made these three config files in
/etc/scrapy.cfg (system-wide),
~/.config/scrapy.cfg ($XDG_CONFIG_HOME) and ~/.scrapy.cfg ($HOME) for global (user-wide) settings.
but It didn't help at all.
what should I do?
I followed the instruction in the first answer by paul trmbrth. There still seems to be a problem though.
seems like I do have a right configuration file in the right place. But I still cannot open scrapy shell with ipython, as you can see in the screenshot. Have any idea?
Another way to configure (or test) the shell used by scrapy shell is the SCRAPY_PYTHON_SHELL environment variable.
So running:
paul#paul:~$ SCRAPY_PYTHON_SHELL=ipython scrapy shell
would use ipython as first choice, whatever setting in *scrapy.cfg you may have.
To check where scrapy is looking for config files, and what it finds, you can start the python interpreter and run what scrapy shell does:
$ python
Python 3.5.1+ (default, Mar 30 2016, 22:46:26)
[GCC 5.3.1 20160330] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from scrapy.utils.conf import get_config, get_sources
>>> get_sources()
['/etc/scrapy.cfg', 'c:\\scrapy\\scrapy.cfg', '/home/paul/.config/scrapy.cfg', '/home/paul/.scrapy.cfg', '']
>>> cfg = get_config()
>>> cfg.sections()
['deploy', 'settings']
>>> cfg.options('settings')
['shell']
>>> cfg.get('settings', 'shell')
'bpython'
If you are inside of the project you can use this:
from scrapy.utils.project import get_project_settings
settings = get_project_settings()
settings.get('IMPORT_API_URL')
If you are outside of the project, you can use this:
from scrapy.settings import Settings
settings = Settings()
settings_module_path = os.environ.get('SCRAPY_ENV', 'project.settings.dev')
settings.setmodule(settings_module_path, priority='project')
settings.get('BASE_URL')

Read from stdin with monkeyrunner

How do I read from stdin with monkeyrunner? I tried the following code.
import sys
print("type something")
something = sys.stdin.readline()
print(something)
I also tried the following:
print("type something")
something = raw_input()
print(something)
In both cases the program prints "type something" but it does not respond after I type something. It seems i am making some silly mistake?
This seems to be a bug with Jython 2.5.3, the version that is included with MonkeyRunner. The issue says Mac OS X but I am able to reproduce on Ubuntu.
To fix it, you can download the Jython 2.5.4rc1 standalone Jar from the Jython website (download link) and copy it into the $SDK/tools/lib directory. Note that the Jython 2.7.0 standalone Jar will not work properly. You don't need to rename the new Jar, but you do need to (re)move the old jython-standalone-2.5.3.jar from the directory.
Another option (if you only need user input) is to use the input function in the MonkeyRunner class.

Programming Python with an EasyPHP server?

How would I be able to configure EasyPHP to use the Python CGI? I have been trying to find information on this for the past while to no avail.
If you have Python 2.7 and EasyPHP 14.1 installed, you may go to the EasyPHP folder ../binaries/apache/cgi-bin/ (where, by the way, you may already have printenv.pl file which is the same stuff for Perl programming).
Create a .py file, let it be printenv.py, with the following content:
#!E:/Python27/python
# -*- coding: UTF-8 -*-
# enable debugging
import cgitb
cgitb.enable()
print "Content-Type: text/plain; charset=utf-8"
print
print "Hello World!"
(In my case E:/Python27/ is the folder where Python installed, so it shoud be changed accordingly.)
In a browser enter: 127.0.0.1/cgi-bin/printenv.py. (The localhost reference may differ but /cgi-bin/printenv.py part remains.)
Than you should see in your browser:
Hello World!
For more information, please, visit Web Python .
It is also recommended to use mod_wsgi instead of CGI technique.