I am very new to Python, and I am attempting to reproduce an example (not necessary to answer the question). If all I have is import threading from within the code I assumed I could just run pip install threading however the module is not found. When I searched for a different package name in the Python package manager I came across hundreds. Why doesn't the pip command work, and how do I know which package to install?
My exact error
:\Users\king\Desktop\_REPOS\misc\stock_analysis\forex\python\pythonv2>python trading.py
Traceback (most recent call last):
File "trading.py", line 1, in <module>
import Queue #pip install queuelib
ImportError: No module named 'Queue'
Version info
Python 3.5 32bit (64 bit OS)
The first hit on google (search: python threading) actually gave me:
https://docs.python.org/2/library/threading.html (the URL itself already indicate it)
This means it's a library module so it should be already available to you without extra installs.
In case your Python is limited in a way and doesn't have it by default, please update your question with your Python version and way it was installed.
For future reference, you were mostly doing the right thing, a lot of modules have the same name as their import statements, but otherwise, in almost all case, a simple Google search will suffice.
Related
I wish to run a package, openquake; however, it was installed separately from Anaconda, which I am using to run python.
[centos modules]$ which python
~/anaconda2/bin/python
I have set openquake up and I believe it's installed correctly, however, when I try to run my script, I receive the following error:
[centos maxdist]$ python ../script.py
Traceback (most recent call last):
File "script.py", line 12, in <module>
from openquake.hazardlib.source import ComplexFaultSource
ImportError: No module named openquake.hazardlib.source
I was wondering if I need to add a line to my script for it to find the openquake module for it to run successfully? In general, what's the best way to run a python package that is installed outside of the main Anaconda python instance? I am trying to avoid having to re-install openquake for Anaconda, as I was having a little bit of difficulty with that work-around.
Thank you.
If both environments, anaconda and default python that you installed the library for have the same python version, then
import sys
sys.path.append(r'/path/to/package')
from openquake.hazardlib.source import ComplexFaultSource
Check if this works. If the package is compiled for different version, then there will be an error. Also, I would suggest you to use one environment and avoid doing this for the sake of simplicity.
I am trying to use the code in this github project: https://github.com/Katharsis/unfrozen_binary
When I try to run the script: python unfrozen_binary_cx_Freeze.py
I receive the following error:
File "/path/to/file/unfrozen_binary-master/common.py", line 20, in <module>
from decompilers.uncompyle2 import uncompyle_file
ImportError: No module named decompilers.uncompyle2
I checked common.py and it imports uncompyle package as shown below:
if python_version[0] == 3:
from decompilers.unpyc3.unpyc3 import dec_module
elif python_version[0] in (1, 2):
from decompilers.uncompyle2 import uncompyle_file
from decompilers.uncompyle2 import Walker
There is no decompilers package available.
However, I already have uncompyle2 installed so, I edited the above code to use uncompyle2 only since I am using Python version 2.7
Now, I receive the ImportError for uncompyle2 even though I have both uncompyle2 and uncompyle6 installed. Even confirmed this with pip show command.
>>> import uncompyle2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named uncompyle2
>>> import uncompyle6
>>>
However, pip show command shows that uncompyle2 is installed:
$ pip show uncompyle2
Name: uncompyle2
Version: 2.0.0
Summary: Python byte-code to source-code converter
Home-page: https://github.com/rocky/python-uncompyle6
Author: Hartmut Goebel
Author-email: h.goebel#crazy-compilers.com
License: MIT
Location: /usr/local/lib/python2.7/dist-packages
Requires: uncompyle6
Is anyone able to get the above github project working?
Please let me know.
Thanks.
Part of your problem is my doing: with pip install of uncompyle2, right now you are getting uncompyle6, not uncompyle2.
This decision was made because at the time this was done, there wasn't anyone who would step up to maintain any (of the many) forks of uncompyle2. The packager of uncompyle2 on pypi wasn't one of the authors, just a packager. So it was really an untenable situation for him.
If someone wants to step up and maintain uncompyle2, they can contact me and I'll transfer uncompyle2 to someone else. The best maintained version of uncompyle2 seems to be the one under the wibiti account.
If you install that from github sources, then change from decompilers.uncompyle2 import to from uncompyle2 import in the unfreeze_binary code.
I see you have opened an issue with the project in question.. That is good! However since that it seems like the only issue that has ever been opened, and this issue was opened a while ago, this suggests that project is dead like many of the uncompyle2 forks and unpyc3 which only handles Python 3.3. (Many python packages packages, like pip, have recently been telling me that they no longer support Python 3.3, so I doubt unpyc3 is of much use nowadays)
The last commit to the unfrozen_binary project is over 4 years ago. So given its low github ratings, the lack of commits and supports, I would expect other problems down the line.
That said, all of this is open source so I guess you or someone else could fork the code and get it working again. If you do that though, I'd suggest using uncompyle6 which supports lots of Python versions including 2.7, 3.3 and current 3.x versions. For that instead of from decompilers.uncompyle2 import you'd use from uncompyle6 import.
Could someone help, please? I can't understand why I see this.
I'm trying to use spwd module from Python. I just imported it, but see this, absolutely unexpected, error when running:
Traceback (most recent call last):
File "./library/system_users.py", line 25, in <module>
import spwd
ImportError: No module named pwd
I thought it should be available by default.
Python 2.7.10
pip 8.1.1 from /Library/Python/2.7/site-packages (python 2.7)
OS X El Capitan 10.11.4
I know sometimes pip install --upgrade pip can help. Unfortunately, not now.
Thank you for the advance.
As you guessed in your comment on this question, spwd is a built-in module, so it is usually built as you compile Python. For this reason, I would guess that spwd simply isn't supported on the system you are using—i.e. OS X 10.11—unless whoever built your installed version of Python made a configuration mistake or manually disabled the module.
However, we can do more than guess about this. When building Python, much of the system-specific configuration is handled in a script called setup.py. Support for many built-in modules is determined in the detect_modules method of the PyBuildExt class; the function contains the following code (taken from here).
if (config_h_vars.get('HAVE_GETSPNAM', False) or
config_h_vars.get('HAVE_GETSPENT', False)):
exts.append( Extension('spwd', ['spwdmodule.c']) )
else:
missing.append('spwd')
We can see that the function adds the Extension 'spwd' (which consists of the spwdmodule.c source file) to the lists of extensions only when config_h_var has either HAVE_GETSPNAM or HAVE_GETSPENT. The strings in config_h_vars correspond to the macros that are defined in the pyconfig.h header file that is generated when you run Python's configure script before compiling.
According to comments generated with the pyconfig.h file, HAVE_GETSPNAM is defined (to 1) if your system has the getspname function, and HAVE_GETSPENT is defined (again, to 1) if your system has the getspent function.
The problem is that OS X 10.11 (and, seemingly, newer versions of macOS) have neither of these functions. (The manual for gnulib confirms this, albeit for an older version of Mac OS X. See this page and this page.) Thus, when compiling Python on OS X/macOS, the spwd is not built, and so you see an ImportError when you try to import it on that system.
dooms's answer suggests installing spwd from Anaconda. Of course, this isn't expected to work since spwd is a built-in module, not a package you would expect to install from a package manager. I also don't see a spwd package on PyPI or any Anaconda channels.
However, since Python does not seem to prevent you from installing a module named spwd (at least when you don't have the built-in spwd), it is conceivable that you could install some sort of drop-in replacement spwd made for macOS. macOS and iOS use /etc/master.passwd instead of /etc/shadow, but maybe it might still be possible to make something work.
Unfortunately, as of this writing, it doesn't seem like any such replacement exists for macOS. I would treat any software that requires spwd as incompatible with macOS.
You should use Anaconda.
Anaconda is a completely free Python distribution (including for commercial use and redistribution). It includes more than 400 of the most popular Python packages for science, math, engineering, and data analysis. See the packages included with Anaconda and the Anaconda changelog.
After that, just type :
conda install spwd
From IDLE, I tried to run a script with a newly installed scrapy 1.0.3.
I'm using a script from a friend whom it worked for (but on Windows, I'm on a Mac).
From the import of scrapy on the first line, I get this error when running the program:
ImportError: No module named twisted.persisted.styles
The whole script, if it's helpful, points to this:
Traceback (most recent call last):
File "/Users/eliasfong/tutorial/tutorial/spiders/medspider.py", line 1, in <module>
import scrapy
File "/Library/Python/2.7/site-packages/scrapy/__init__.py", line 27, in <module>
from . import _monkeypatches
File "/Library/Python/2.7/site-packages/scrapy/_monkeypatches.py", line 20, in <module>
import twisted.persisted.styles # NOQA
ImportError: No module named twisted.persisted.styles
Any suggestions on how to tackle this problem?
Just try to force the update of twisted :
pip install twisted --upgrade
That works for me with python3.4 and Scrapy==1.1.0rc1
Either twisted is installed on your mac (I highly doubt it since it's not a standard library) and for whatever reason the IDE (i'm assuming that's what you mean since you typed "idle") or the terminal you are in doesn't have your updated environment variables, meaning it doesn't understand where your default python libraries are (again I highly doubt it), or you simple do not have twisted installed on your mac. If it's not installed you have a couple of options:
The easiest way to install a python package is through pip.
If that not an option you can try homebrew which is another package manager for macs. It offers an easy way to install packages correctly.
If that still is not an option for you or you simply don't want to attempt that you can download twisted directly from here (the .bz2 since you're on a mac), click on it and it should unzip it for you. Then just run setup.py and it should install it in the correct location on your mac.
If that still doesn't work and you have decent knowledge of unix. Use the "locate" command on the terminal and find out where your dist-packages directory is and put the source for twisted in there directly and then attempt to import twisted in your IDE or in the python interpreter to verify that it is installed.
note: If you're still having problems after it is installed trying restarting your IDE or messing with some setting to make sure your IDE has the right environment and python path. Hope that helps!
It could be related to having installed Python without bzip2. I had the same error and this helped me, see the accepted answer here:
Installing Twisted through pip broken on one server
Had this exact thing on FreeBSD. Solution (as root/sudo):
chmod -R go+rX /usr/local/lib/python2.7/site-packages
Some directory permissions weren't set up right on install.
I'm installing a Python (2.7.8) environment locally in my home folder on a server, in order to use newer versions of Python and some of its libraries (Numpy, Theano) together with OpenBLAS. For this, I first installed Python in the folder usr in my home directory (/home/my_home/usr/) as described here:
https://mail.python.org/pipermail/tutor/2002-March/012903.html
The installation seems to have gone smoothly. I checked this by starting the Python interpreter, which displays the right version on startup.
Following this, I installed OpenBLAS into /home/my_home/opt folder as described here:
Compiling numpy with OpenBLAS integration
... which also didn't give me any errors. However, now when I try installing Numpy (according to the instructions in the above link), I get the following error:
Traceback (most recent call last):
File "setup.py", line 22, in <module>
import subprocess
File "/home/ext_sxc/usr/lib/python2.7/subprocess.py", line 427, in <module>
import select
ImportError: No module named select
I suppose the straightforward thing to do is to find the package for select, compile and install it. I'm not sure if this is the right thing to do because the last time I installed Python 2.7.6 locally in a home directory, there were no such errors. As I understand, the select module should have been installed along with Python.
This also happens when I try installing IPython in a similar way in my home folder. The library which gives the ImportError is different.
I'm wondering if these are related to a more general mistake I may have made while installing Python. I'd appreciate any advice on this issue. Please let me know if any additional information would help. Thanks!