Python module "preprocess" - does that exist? - python

In my python code I want to use a module called "topicmodels" (that can be found here https://github.com/sekhansen/text-mining-tutorial). The problem with this module is that whenever I want to "import topicmodels" in my Python code, I get the error message:
ImportError: No module name preprocess, more specifically in that topicmodels module is a Python file init.py that contains the line " from preprocess import * ". I googled and did not find a python module called preprocess - can anybody help me out on this?
(I am using Kubuntu and Python 3.5.2 | Anaconda 4.2.0).
Thanks a lot for any help!

This code is written for Python 2. You're on Python 3. The failing import is an implicit relative import, which Python 3 prohibits.
Run it on Python 2.

pip install preprocessing
Reference: https://pypi.org/project/preprocessing/

Related

Python gives error when importing simple C extension module

On windows I have built a very simple "hello world" C extension (the file hello.c from this site https://gist.github.com/physacco/2e1b52415f3a964ad2a542a99bebed8f). Using VS2015 I successfully obtain hello.dll. The problem is that I can't figure out how to import this file/module.
In the python shell (python 3.7) I have made sure that I'm in the same folder as the hello.dll. I have also made sure that sys.path() contains the folder path. But when I write "import hello" I get an error "ModuleNotFoundError: No module named 'hello'"
Does anyone has an idea of what is wrong is this very simple setup?
Update:
When trying to import a module that does not exist the ModuleNotFoundError is reported. After renaming the hello.dll to hello.pyd an ImportError is returned. So it seems like it tries to actually load the module.
Python compiled modules on Windows have the extension .pyd, not .dll. If you'd built it using setup.py the file would be built with the correct name. However, you built it yourself and gave it a name that Python doesn't recognise as a module.
In terms of the build command: you have to link it with libpython. You don't look to be doing this. The error you report is definitely one that you can get if the module is not linked against all its dependencies.
I know you don't want to use setup.py, however I'd use it at least once just to see what it does and if it works. You'll then at least have a command that you can copy with a working set of options.

J meter with Python : how to import the packages

Iam new bee to the jmeter
My code is working in the Python 2.7 with importing additional packages Dateutil, parser .
Problme : But when I am trying to run same code in the J Meter-JSR-223 PreProcessors , an error saying No module named dateutil in.
So , I have tried another approach to use Jython .
Installed the Jython ( downloaded the dateutil) and provide the packages reference under
import sys
sys.path.append('C:/Jython27/Lib/site-packages')
sys.path.append('C:/Jython27/Lib/site-packages/python_dateutil-2.4.2-py2.7/dateutil')
sys.path.append('C:/Jython27/Lib/site-packages/python_dateutil-2.4.2-py2.7/dateutil')
Now packages error is gone but string syntax error is present .
java.sql.Date' object has no attribute .
I believe dateutil package can be picked up from CPython as it doesn't require any extra wrappers for Java.
Install dateutil normally using pip like:
pip install python-dateutil
Add site-packages folder of Python (not Jython) installation to sys.path like:
sys.path.append("C:\Python27\Lib\site-packages")
That's it, now you should be able to use dateutil module functions from the JSR223 Test Elements:
Be aware that invoking Python scripts via Jython interpreter is not the best idea from performance perspective and if you're about to invoke your Python code only limited number of times and/or with a single thread - it might be better to go for the OS Process Sampler.
If you plan to use the Python code to create the main load - consider using Locust tool instead of JMeter. If you don't want to change JMeter a good approach would be rewriting your Python code in Groovy - it will be way better from the performance perspective.
hi please find follwing
import sys
sys.path.append('C:/Python27/Lib/site-packages')
sys.path.append('C:/Python27/Lib/site-packages/python_dateutil-2.4.2-py2.7/dateutil')
from dateutil.parser import *
sourceDateTimeOfEvent = ""
dateTimeOfEvent = ""
a=parse('2016-07-01 13:00:00')
sourceDateTimeOfEvent = a.isoformat()+"+05:30Z"
dateTimeOfEvent = a.isoformat()+ "Z"
vars.put("sourceDateTimeOfEvent", sourceDateTimeOfEvent)
vars.put("dateTimeOfEvent", dateTimeOfEvent)
This sourceDateTimeOfEvent and dateTimeOfEvent considered as two variables and passed it to the json file

Importing winappdbg gives ModuleNotFoundError for breakpoint in PyCharm?

Whenever I try to just import winappdbg it gives me an error ModuleNotFoundError: No module named 'breakpoint'. So, I tried installing breakpoint and that gives me another error ModuleNotFoundError: No module named 'ConfigParser' and I've installed configparser several times and still get the error. (Can't find capital ConfigParser) I'm using Windows 10/PyCharm Community Edition 2017.2.3/python 3.6.3
WinAppDbg is only for Python 2.x, it does not work on Python 3.x. Honestly, I had no idea it would even let you import it.
All those import errors are happening not because of missing dependencies (also, no idea there were similarly named modules in pip), they are submodules of WinAppDbg itself. Since Python 3 has a different syntax to specify those, it tries to load them as external modules instead. I suppose you could fix that in the sources by prepending a dot before every submodule import, but I'm guessing more stuff would break down the road (string handling for example is radically different and that would affect the ctypes layer).
TL;DR: use Python 2.x.

Getting apihelper module from Dive into Python

I have a problem with chapter 4 of this book. I run python shell (IDLE, python 2.7) and try to import apihelper module, but I keep getting traceback saying
No module named apihelper
I downloaded the code from Pilgrim's site, but it still doesn't work. What do I miss?
That's because your Python interpreter doesn't know where did you download apihelper module, and it cannot import it.
More about where does import look for packages you can read here in Dive into Python book.

import Error while importing python nltk module in node.js using "python-node" module

I am trying to import python natural language processing toolkit nltk in node.js using node-python mentioned here: https://npmjs.org/package/node-python
The commands i am giving are similar as mentioned on the npm module site:
var python = require('node-python');
var os = python.import('os');
i am getting the following error:
Error: /usr/lib/python2.7/lib-dynload/datetime.so: undefined symbol: PyExc_SystemError
at repl:1:25
at REPLServer.self.eval (repl.js:109:21)
at rli.on.self.bufferedCmd (repl.js:258:20)
at REPLServer.self.eval (repl.js:116:5)
at Interface.<anonymous> (repl.js:248:12)
at Interface.EventEmitter.emit (events.js:96:17)
at Interface._onLine (readline.js:200:10)
at Interface._line (readline.js:518:8)
at Interface._ttyWrite (readline.js:736:14)
at ReadStream.onkeypress (readline.js:97:10)
I am using python2.7.2
After much search i found that this is a known bug in python2.7 and found a similar problem when importing from C here is the what i found:
similar error found while importing python datetime module from C
The problem seems to be in the datetime.so module, i was thinking of getting the updated version of the datetime module and compiling it separately to make it work. I am still looking for that module and comple instructions. I would really appreciate If anyone has a better suggestion to resolve this or even help me locate the place to find this datetime module and its compile instructions. I really don't want to compile the whole python to make it work.

Categories