ModuleNotFoundError: No module named 'hotshot' - python

I am trying to port python 2.7 code to python 3.7 code
I am seeing an "import hotshots" in a file but getting a
ModuleNotFoundError: No module named 'hotshot'
I can't seem to find that module anywhere online. Is this a python 2.7 specific package replaced with something else ? I had that case with cStringIO
Additional info : this is implemented in a Django project. Maybe an older Django lib ? I am trying to port this code from Django 1.8 to 2.2
What I tried to do :
- pip install --upgrade hotshot
No matching distribution found for hotshot
Looking for hotshot on The Python Package Index
No library with that name
What it is used for ? The only line where it is used is
prof = hotshot.Profile(final_log_file)
The whole project code is available here :
https://github.com/EbookFoundation/fef-questionnaire,
the file using "hotshot" is "profiler.py". Additionnally, there are no "hotshot.py" file in the whole project.

Finally found something. hotshot was a Python profiler (https://docs.python.org/2/library/profile.html)
From https://docs.python.org/2/library/hotshot.html :
hotshot was an experimental C module that focused on minimizing the
overhead of profiling, at the expense of longer data post-processing
times. It is no longer maintained and may be dropped in a future
version of Python.
I simply have to replace hotshot by a newer Python profiler, compatible with Python 3 :
https://docs.python.org/3/library/profile.html
So either profile or cProfile.

Related

Python: Alternative for web.py on python3

I tried installing web.py module via pip, but I got an import error. Specifically
import utils, db, net, wsgi, http, webapi, httpserver, debugerror
ImportError: No module named 'utils'
So I realized that it had something to do with the fact that web.py is not compatible with python3.x. So the question is, what alternatives do I have? Would I be better of installing python 2.7+ alongside python3? Or is there a way I could use this module online with a python 2.7+ interpreter?
Right. The problem is web.py is not yet compatible with python3. A new version is on it's way, but you need to consider your current requirements. Python2 can easily live with python3, so that's a very viable option. So, if you're looking for near-term use & you don't want to learn something else (like bottle.py) feel free to use web.py and python27.
If you're experimenting and want to try web.py with python3, Anand has reported that python3 is almost ready. Install with:
pip install web.py==0.40.dev0

jython can't find 3rd party python package (python installed using miniconda)

I have a prototype written in Python that I need to port into Java to put into production. Python 2.7.10 has been installed using miniconda. The prototype uses a 3rd party library nltk that I installed using pip.
To void rewriting the code from scratch, at least initially, I want to first try call the prototype code directly from Java using jython.
When I try executing a command like
java -jar jython-standalone-2.7.0.jar myPrototype.py
I get
Traceback (most recent call last):
File "myPrototype.py", line 4, in <module>
from nltk import AlignedSent
ImportError: No module named nltk
It works fine when I run python myPrototype.py.
Is there a way of configuring my jython install so that it can find all 3rd party packages that I've added to my python install? I realize that some of those might not run in jython but at least I want to have access to those that do.
The bulk of NLTK is Python code so you should be able to use it from Jython as long as it's in your module search path. If you are on unix just add a link to your nltk in site-packages to the current folder. Or look into the documentation here: http://www.jython.org/jythonbook/en/1.0/ModulesPackages.html
NLTK needs to be able to load its data for some stuff. You may want to either make al link to your nltk_data from your home to the current folder or see this answer to set it from code: How to config nltk data directory from code?

Installing mesos egg for python 2.7

I've installed mesos 0.26 successfully on a vm machine.
The installation has been performed on an ubuntu trusty thar system
by following this manual:
https://open.mesosphere.com/getting-started/install/
So far so good. I wanted to write a tiny python framwork.
For this I need to install the eggs via easy_install:
(I've downloaded the eggs accordingly for the trusty thar ubuntu and the 0.26 mesos):
wget http://downloads.mesosphere.io/master/ubuntu/14.04/mesos-0.26.0-py2.7-linux-x86_64.egg
easy_install mesos-0.26.0-py2.7-linux-x86_64.egg
all went fine, however, if I start python in the shell
and type in
import mesos.interface
I get the message: ImportError: No module named interface
As someone suggested, it may be that there is no longer a binding for python, or that they have renamed the API calls. Well, I looked in the version updates here:
http://mesos.apache.org/documentation/latest/upgrades/
Since the transition from 0.19.x to 0.20.x there hasn't been any changes regarding the mesos.interface part, or at least they are not mentioning it here.
To increase the confusion I also get the following error message when I'm typing in python: import mesos.native
There I receive: ImportError: No module named interface.mesos_pb2. To put it into a nutshell: what is going wrong here, and how can it be fixed? And yes, I've googled various web pages, with terms such as "mesos python bindings", mesos +api +python, etc. And yes, I have also consulted the official mesos webpage. There are nice refences for Java and C++ but not for python, or at least they are very well hidden.
Thanks in advance for any hints.
Solved. For what reasons ever:
export PYTHONPATH=${PYTHONPATH}:/usr/lib/python2.7/site-packages/
is required to set the PYTHONPATH. After that step it works like a charm.

how to deal with python projects on a freebsd (freenas) system

I'm struggling with executing a python script on my freenas (freebsd) environment.
I created a Jail, where I installed python via
pkg install python
and tried to execute the program with the command
python filename.py
But now its mentioning that it requires a specific module
ImportError: No module named simplejson
which I also installed via
pkg install ...
the next attempt to execute the script mentioned a different module.
Is it really the case for python, that you have to install each module per request from an executed program? Or is there a way to determine which module the 3rd party program needs and install it in upfront?
And how do you search for the corresponding module in the repo? Because for the missing sqlite3 module I had to write
pkg install databases/python-sqlite3
How do I get now the correct name for the simplejson module which is mentioned before?
Can you help me out there?
The first questions where already answered in the comments section. Here is the answer to the last question:
FreeBSD ports of python modules usually follow the convention of "py-" + modulename. The corresponding packages are usually named "py"+ python version + "-" + modulename
So it is py-sqlite3 and py-simplejson ports which install "py27-simplejson" and py27-sqlite3 for python 2.7.
Note: currently modules are only packaged for the default python version, for non-default python versions the modules have to be installed from the ports collection.

Using Module for different python version

The default version of python (ie, one that opens on typing "python" in command line) is 2.6 on my server. I also have 2.7 installed. How do I import a module, in this case numpy, in python2.7? When I try to import right now, it gives me an error -
ImportError: No module named numpy
Is there any workaround, apart from downloading the package and doing a build install?
I agree with the comment above. You will have to compile it separately. I once tried a hack of importing and modifying the sys.path however I ran into issues with the .so files.

Categories

Resources