I have a python script that used to run, although since moving servers at work it now throws up a strange error:
>>> import _md5
ImportError: No module named _md5
The general setup is all correct, as is my python path and seemingly everything else. I was told that I need to install the relevant RPM for this to work, but have no idea what this might be - could anyone please point me in the right direction?
These machines have a setup that prohibits me using yum, so I need to make a request to those maintaining the system about which RPM I want installed.
Based on extra bit of information from the OP, they use Python 2.5+ on the new server.
Suggested remedy is to use standard hashlib module. Which provides MD5 hash implementation among other things.
Install openssl-devel and rebuild.
Or better yet, build your own Python package and deploy everywhere.
Related
I have no idea why this is so frustrating, but I have literally pulled out a few clumps of hair in rage because this just refuses to work and I honestly do not have the slighest clue on what to do. I am trying to use the winshell module for a quick python programming I am using. I am new to python and just started trying it today. I have tried to install the library manually, and through pip. pip claims the module is downloaded, and I can see it in the lib folder. No matter what I do I get this error when I try to run my code:
import winshell
ModuleNotFoundError: No module named 'winshell'
what on earth must I do to get this to work I am at my wits end here and I feel like I'm going to break something
You have to install the library with:
pip install winshell
I just tested with pip3 install winshell and it worked.
Python interpreter search for modules in the set of directories that you can see with:
import sys
print(sys.path)
I recommend you take a look to see if the directory where you are seeing the library in lib is include in that list.
Might be useful to you read: The Module Search Path
I got this simple problem and I can't find the answer anywhere, I'm wasting a lot of time!
I did a Python programm on Linux (which works OK), but when I try to run it on Windows, there are too problems with libs...
I have installed the libs I need (dateutil, lxml, xmlrpclib...) in C:\Python34\Lib\site-packages. But then, they don't work as they do on Linux. For example:
from dateutil.tz import tzlocal
Gives me next error:
File "C:\Python34\lib\site-packages\dateutil\tz.py", line 9, in module
from six import string_types, PY3 ImportError: No module named 'six'
That is, they are not finding the other modules... why???
Have you try this ?
http://www.instructables.com/id/How-to-install-Python-packages-on-Windows-7/
Maybe it can help
It looks like you're using Python 3.4 which comes with pip. pip is a tool for installing packages and any dependencies they might have (like the srting_types module from your error message). I'd suggest learning how to use it because it resolves most of the packaging problems with you needing to moving things around yourself. See an answer from a different question to learn more about pip.
There are some packages that need to be compiled. This can be difficult on Windows 7 if you don't have the proper toolchain set up to compile packages. I'd recommend Christoph Gohlke's wonderful collection of installable packages for Windows. You just need to make sure to grab the right version. Since 3.4 is still relatively new, some packages may not be available, so be warned.
I'm trying to use the check-html flag with linkchecker. It gives an error that the tidy module is not installed. If I say tidy at a command line I can use it. I have MacPorts installed and have installed just about every option for libtidy or tidy that has to do with python. I'm thinking it has to do with a $PATH issue or something.
So if I am using python26 and I go into python and then say import tidy there are no errors and all is well. If I use python27 I get errors when I say import tidy. I'm assuming because I installed py26-utidylib py26-pytidylib. There were no py27s. I don't mind being in python26. So it appears if I am in python26 I should be able to run tidy.
But when I run linkchecker it says the tidy module is not installed. When I say which python it says my location is /opt/local/bin/python. Do I need to export the $PATH or $PYTHONPATH or something for it to work?
if you have 2 python compilers running, be sure you use the right one with the "python"-command.
you can see the used interpreter-version if you access the interactive-console with "python".
and you're right, the py26-...-library is for the python2.6 version. if there is no precompiled version you can always compile the library from the source for the required python-version. or at least, you can try.
but here you have to be sure to choose the right python-interpreter to execute the setup-process.
if you want the library for the 2.7-version you have to build it with 2.7-version.
you can also always check the used paths in which the current running python-interpreter is looking for modules, through the interactive python console:
python
>>> import sys
>>> sys.path
i assume you have the library installed for the wrong version, has import the wrong module ... or using it wrong :/.
maybe you could supply your code example!?
My employer has a dedicated module1 we use for internal unit / system test; however, the author of this module no longer works here and I have been asked to test some devices with it.
The problem is that pyfoo requires an ancient version of twisted (v8.2.0) and it imports twisted in 33 different files. I tried running pyfoo's unit tests under v11.0.0 and I don't even see TCP SYN packets2. Unfortunately, I have already got twisted v11.0.0 installed on my lab linux server and I have my own code that depends on it.
To solve this problem, I have only come up with the following options:
Option A. Install a new version of python, install virtualenv, and then install an old version of twisted under the virtualenv. Only run the tests requiring pyfoo under this new version of python.
Option B. Edit all 33 of the files with the following: DIR = '../'; sys.path.insert(0, DIR) and install the old version of python in the appropriate directory below the source.
Option C. Attempt to fix pyfoo to use v11.0.03
Are there any options I am missing? Is there a more elegant way to solve this problem, besides Option A, above?
**END-NOTES:**
Let's call it pyfoo for sake of argument
The unit tests connect to one of our local lab servers and exercises basic telnet functionality
This option is almost a non-starter... pyfoo is not trivial, and I have a short deadline for this work.
A better version of option B. would be to replace
import twisted
by
import pkg_resources
pkg_resources.require("Twisted==8.2.0")
import twisted
which will arrange for the correct version of twisted to be imported, so long as it's installed, and raises an exception otherwise. This is a more portable solution.
This won't work, though (nor would any other variaton of option B), if twisted gets imported before the pkg_resources.require gets called; twisted will already be in sys.modules
OP Edit: Minor syntax correction, per pkg_resources docs
If SingleNegationElimination's solution doesn't work, be aware that you don't need to replace all 33 instances of the import; you only need to modify sys.path at the entry points; e.g. you could target just your module's __init__.py files.
There you would insert e.g.
import sys
sys.path.insert(0, DIR)
I can't tell you what is best in your situation, but you might be able to consider:
Option D: run it in a virtual machine (eg. with Windows 7)
Option E: install old version of python/twisted on another machine
It took me a bit of trial and error to fix my situation; which involved the accepted answer and it's additional comments (mentioning adding _requires_)
__requires__= 'twisted==8.2.0'
import pkg_resources
pkg_resources.require("twisted==8.2.0")
import twisted
You should do uninstall and install before import.
First,
!pip uninstall igraph -y
!pip uninstall python-igraph -y
!pip install python-igraph==0.9.6
!pip install cairocffi
Then,
import igraph
print(igraph.__version__)
% 0.9.6
I'm just starting out with Python, and have found out that I can import various libraries. How do I find out what libraries exist on my Mac that I can import? How do I find out what functions they include?
I seem to remember using some web server type thing to browse through local help files, but I may have imagined that!
From the Python REPL (the command-line interpreter / Read-Eval-Print-Loop), type help("modules") to see a list of all your available libs.
Then to see functions within a module, do help("posix"), for example. If you haven't imported the library yet, you have to put quotes around the library's name.
For the web server, you can run the pydoc module that is included in the python distribution as a script:
python /path/to/pydoc.py -p 1234
where 1234 is the port you want the server to run at. You can then visit http://localhost:1234/ and browse the documentation.
Every standard python distribution has these libraries, which cover most of what you will need in a project.
In case you need to find out if a library exists at runtime, you do it like this
try:
import ObscureModule
except ImportError:
print "you need to install ObscureModule"
sys.exit(1) # or something like that
You can install another library: yolk.
yolk is a python package manager and will show you everything you have added via pypi. But it will also show you site-packages added through whatever local package manager you run.
just run the Python interpeter and type the command
import "lib_name"
if it gives an error, you don't have the lib installed...else you are good to go
On Leopard, depending on the python package you're using and the version number, the modules can be found in /Library/Python:
/Library/Python/2.5/site-packages
or in /Library/Frameworks
/Library/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages
(it could also be 3.0 or whatever version)...
I guess it is quite the same with Tiger
Considering that in every operating system most of python's packages are installed using 'pip' (see pip documentation) you can also use the command 'pip freeze' on a terminal to print a list of all the packages you have installed through it.
Other tools like 'homebrew' for macOS (used when for some reason you can't install a package using pip) have similar commands, in this specific case 'brew list'.