I'm trying to build an application using the new-ish Pyramid framework. I'm new to Pyramid and have no idea what Zope does (the importance of which will become apparent). I followed the basic tutorial, but when I try to run the application I get this traceback:
Traceback (most recent call last):
File "tasks.py", line 4, in <module>
from pyramid.config import Configurator
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pyramid-1.2-py2.6.egg/pyramid/__init__.py", line 1, in <module>
from pyramid.request import Request
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pyramid-1.2-py2.6.egg/pyramid/request.py", line 1, in <module>
from zope.deprecation import deprecate
ImportError: No module named deprecation
I tried install Pyramid using setuptools:
sudo easy_install pyramid
Which, among a lot of other output included this:
Searching for zope.deprecation
Reading http://pypi.python.org/simple/zope.deprecation/
Best match: zope.deprecation 3.5.0
Downloading http://pypi.python.org/packages/source/z/zope.deprecation/zope.deprecation-3.5.0.tar.gz#md5=1e7db82583013127aab3e7e790b1f2b6
Processing zope.deprecation-3.5.0.tar.gz
Running zope.deprecation-3.5.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-ZiLy8j/zope.deprecation-3.5.0/egg-dist-tmp-yGFSor
Adding zope.deprecation 3.5.0 to easy-install.pth file
Which I thought should cover it.
I also tried installing zope via macports:
sudo port install zope
sudo port install py26-zopeinterface
I've also tried to run sudo port load zope before running the script, but no help there.
I also tried downloading the source from http://pypi.python.org/pypi/zope.interface and building it manually in directory.
Any ideas what I'm doing wrong?
----EDIT----
One guess is that setuptools in installing its zope components into my system's default Python framework (which is an Enthought distribution), but my default python environment is the one that Macports installed, so perhaps the Macports zope module has some but not all of the components, such as zope.deprecate.
The documentation includes information about how to use a virtualenv to install Pyramid. It's very, very recommended to use a virtualenv this way. System packages already installed in your main Python will have weird interactions with Pyramid's requirements.
You may get an answer from someone more familiar with Pyramid, but the problem here is that pyramid.request depends on zope.deprecation and it isn't installed/available. You'll have to elaborate much more on "I've tried installing zope using ..." for me to help you more.
Be sure you're running pyramid from the same python that you did the installation to. If that's the case then the zope.deprecation package should be installed there. What do you get from python -c "import zope.deprecation ; print import zope.deprecation"?
I solved it by installing zope.deprecation OS package:
sudo apt-get install zope.deprecation
Just re-install pyramid to fix.
I have had problem with moving class into sub-module.
The problem was another component of software was importing class from "OLD" module. And also there was cycling problem with inheritance.
So the solution was to use zope.deferredimport. The code looks like this:
import warnings
import zope.deferredimport
warnings.simplefilter("default")
zope.deferredimport.initialize()
zope.deferredimport.deprecated(
"Import from openprocurement.contracting.core.tests.base instead",
BaseContractWebTest='openprocurement.contracting.core.tests.base:BaseContractWebTest',
)
So now, when any component of software, that uses import from "OLD"
module doesn't get ImportError. Class is imported from "NEW" module. And warning is displayed like this:
DeprecationWarning: BaseContractWebTest is deprecated. Import from openprocurement.contracting.core.tests.base instead
So this is it. The main part zope.deferred took care of cycle imports. That saved my life.
Related
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.
After installation, I would like to make soft-links to some of the configuration & data files created by installation.
How can I determine the location of a new package's files installed from within the package's setup.py?
I initially hard-coded the path "/usr/local/lib/python2.7/dist-packages", but that broke when I tried using a virtual environment. (Created by virtualenv.)
I tried distutils.sysconfig.get_python_lib(), and that works inside the virtualenv. When installed on the real system, however, it returns "/usr/lib/python2.7/dist-packages" (Note the "local" directory isn't present.)
I've also tried site.getsitepackages():
Running a Python shell from the base environment:
import site
site.getusersitepackages()
'/home/sarah/.local/lib/python2.7/site-packages'
site.getsitepackages()
['/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages']
Running a Python shell from a virtual environment "testenv":
import site
site.getsitepackages()
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'module' object has no attribute 'getsitepackages'
I'm running "Python 2.7.3 (default, Aug 1 2012, 05:14:39)" with "[GCC 4.6.3] on linux2" on Ubuntu. I can probably cobble something together with try-except blocks, but it seems like there should be some variable set / returned by distutils / setuptools. (I'm agnostic about which branch to use, as long as it works.)
Thanks.
I haven't found the "correct" way of doing this, but I have found a couple tricks that seem almost-correct. One method only works on install; the other only works if the package is already installed.
For install, I use the object returned by setuptools.setup():
from setuptools import setup
s = setup([...])
installation_path = s.command_obj['install'].install_lib
(This only works during install since you need a valid Distribution object for those attributes to exist. AFAIK, the only way to get such an object is to run setup().)
On uninstall, I use the file attribute of the package, as suggested by #Zhenya above. The only catch is that when I run ./setup.py uninstall to get rid of package, I usually have directories ./package/, ./build, ./dist, and ./package.egg-info/. (The "uninstall" option is caught by my code without calling setup(). It runs a manually-created script to delete the package files.) These can redirect the python interpreter to some place other than the globally-accessible repository I'm trying to get rid of. Here's my hack to handle that:
import imp
import sys
from subprocess import Popen
from os import getcwd
Popen('rm -r build dist *.egg-info', shell=True).wait()
oldpath = sys.path
rundir = getcwd()
sys.path.remove(rundir)
mod = imp.find_module(PACKAGE)
p = imp.load_module(PACKAGE, mod[0], mod[1], mod[2])
sys.path = oldpath
installation_path = p.__file__
(This doesn't work during install since - I think - Python only inventories modules when it starts, so find_module() won't find the just-installed package unless you exit python and come back in.)
I've tested both install and uninstall on a bare environment and a virtual environment (from virtualenv 1.9.1). I'm running Ubuntu 12.04 LTS, Python 2.7.3, setuptools 0.6c11 (in the bare environment) and setuptools 0.7.4 (in virtualenv).
This will probably not answer your question, but if you need to access the source code of a package you have installed, or any other file within this package, the best way to do it is to install this package in develop mode (by downloading the sources, putting it wherever you want and then running python setup.py develop in the base directory of the package sources). This way you know where the package is found.
Ubuntu Maverick w/Python 2.7:
I can't figure out what to do to resolve the following import error:
>>> import ssl
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/ssl.py", line 60, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: No module named _ssl
UPDATE:
I recompiled the source. I was unable to figure out how to add the --with-ssl option the answers below mention, instead I got this to work by editing the lines regarding SSL in /Modules/Setup.dist.
Unrelated to the original question, but because this is the first Google result... I hit this on Google AppEngine and had to add:
libraries:
- name: ssl
version: latest
to app.yaml per: https://cloud.google.com/appengine/docs/python/sockets/ssl_support
Please NOTE: This seems to work upto Python version 2.7.9 but not for 2.7.10 or 2.7.11.
Did you build the Python from source? If so, you need the --with-ssl option while building.
Since --with-ssl is not recognized anymore I just installed the libssl-dev.
For debian based systems:
sudo apt-get install libssl-dev
For CentOS and RHEL
sudo yum install openssl-devel
To restart the make first clean up by:
make clean
Then start again and execute the following commands one after the other:
./configure
make
make test
make install
For further information on OpenSSL visit the Ubuntu Help Page on OpenSSL.
If you built Python from source, this is just a matter of dependencies: since you miss OpenSSL lib installed, python silently fails installing the _ssl module. You can see it in the final report of the make command:
Python build finished, but the necessary bits to build these modules were not found:
_bsddb _sqlite3 _ssl
_tkinter bsddb185 dbm
dl gdbm imageop
sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
Installing OpenSSL lib in any of the standard lib paths (/usr/lib, /usr/local/lib...) should do the trick. Anyway this is how I did :-)
I had exactly the same problem. I fixed it without rebuilding python, as follows:
Find another server with the same architecture (i386 or x86_64) and the same python version (example: 2.7.5). Yes, this is the hard part. You can try installing python from sources into another server if you can't find any server with the same python version.
In this another server, check if import ssl works. It should work.
If it works, then try to find the _ssl lilbrary as follows:
[root#myserver]# find / -iname _ssl.so
/usr/local/python27/lib/python2.7/lib-dynload/_ssl.so
Copy this file into the original server. Use the same destination folder:
/usr/local/python27/lib/python2.7/lib-dynload/
Double check owner and permissions:
[root#myserver]# chown root:root _ssl.so
[root#myserver]# chmod 755 _ssl.so
Now you should be able to import ssl.
This worked for me in a CentOS 6.3 x86_64 environment with python 2.7.3. Also I had python 2.6.6 installed, but with ssl working fine.
The underscore usually means a C module (i.e. DLL), and Python can't find it. Did you build python yourself? If so, you need to include SSL support.
I am writing this solution for those who are still facing such issue and cant find the solution.
in my case, I am using
shared hosting (Cpanel Access) Linux CentOS.
I was facing this issue
No module named '_ssl'
I tried for all possible solutions but as you know sometimes things don't work for you and in hosting you don't have access to fully root and run queries.
even my hosting provider did for me.. but NO GOOD RESULT.
so how I solved if you are using shared hosting and you have deployed your Django App using
Setup Python App
You only have to downgrade your Python Version, I downgraded from
Python 3.7.3
(As Python 3.7 does not have SSL module in it)
To
Python 3.6.8
through Setup Python App.
Hope it will be helpful for someone with the same issue,
Either install the supplementary packages for python-ssl using your package manager or
recompile Python using -with-ssl (requires OpenSSL headers/libs installed).
On Solaris 11, I had to modify setup.py to include /opt/csw/include/openssl in the SSL include search path.
Uwe
I am trying to follow the instructions for the accepted answer to "PyObjC development with Xcode 3.2". I will repost them here since I don't have enough rep to comment on the actual question:
Here's what I have done to get PyObjC working in Snow Leopard:
Using the Finder, I went to Go > Connect to Server... and connected to http://svn.red-bean.com/pyobjc/trunk/pyobjc/pyobjc-xcode/ as a guest.
I then made a folder called Xcode on my local system at ~Library/Application Support/Developer/Shared/Xcode/. (You may already have this folder, but I hadn't customized anything for myself yet).
I copied the File Templates folder from the red-bean server into my new Xcode folder.
Copied the Project Templates folder to some other place, for example, the Desktop.
Using the Terminal, navigated to the temporary Project Templates folder on my Desktop and ran this command to "build" the template.:
$ cd ~/Desktop/Project\ Templates/
$ ./project-tool.py -k -v --template ~/Desktop/Project\ Templates/Cocoa-Python\ Application/CocoaApp.xcodeproj/TemplateInfo.plist Cocoa-Python\ Application ~/Library/Application\ Support/Developer/Shared/Xcode/Project\ Templates/Cocoa-Python\ Application
When I try to run the line that starts with ./project-tool.py, I get the following error in Terminal:
Traceback (most recent call last):
File "./project-tool.py", line 22, in <module>
from Foundation import NSDictionary
ImportError: No module named Foundation
I am running Snow Leopard and have installed Xcode 3.2.1 and have read that this module should already be installed and working. I've read that you can test if the PyObjC modules are working by running >>> import objc in the Python command-line. When I run this, I get:
>>> import objc
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named objc
Could anyone help me dispel this error? It seems like I should be able to do all of this automatically with my Snow Leopard installation, but I can't.
I had the same problem. Mine was caused I think by using homebrew to install my own Python to tinker with.
Because I was worried about mixing python versions, rather than creating the link as described above, I installed a new pyobjc using:
$ pip install pyobjc
For interest, from (http://pythonhosted.org/pyobjc/)
The PyObjC project aims to provide a bridge between the Python and Objective-C programming languages.
Okay, it turned out that, amending mjv's answer, I was able to get it working by typing
export PYTHONPATH="/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/PyObjC/"
before executing the ./project-tool.py line. I still find it ridiculous that I had to do this and if anyone can see why, I would be delighted to know.
Doing this also got the
>>> import objc
line working.
It's because PyObjC is there :
/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC
Edit :
I found how to make "import objc" work, just :
export PYTHONPATH="/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/"
It will add all the directories to the python path (sys.path)
for python 2.7
export PYTHONPATH="/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/"
One of two things:
Either the Fundation module doesn't exists
Or Python interpretor doesn't know when to find this file
Python looks for modules in the PythonPath
See this SO question for more details on how Python Path is created etc.
Run python -v to trace import statements, this work for interactive mode too.
I could access a Python installation with Foundation on my OSX by running /usr/bin/python file-to-run.py
remove your python or remove site-packages/Foundation | site-packages/foundation
pip3 install pyobjc
the name Foundation is in conflict with https://pypi.org/project/foundation/
I found the foundation folder in /usr/local/lib/python3.9/site-packages/ next to the AppKit folder. After renaming it to Foundation (with uppercase F), the import worked. The Filesystem is not case-sensitive but it seems some part of the import implementation is.
Saw it mentioned in another comment and I too ran into this problem due to installing Python via homebrew. My pyobjc installation wound up going to the Python homebrew installation, yet my pythonpath was linked to the Python that comes bundled with macOS, so there was this big disconnect and I had no luck getting pythonpath re-routed in .zshrc or .zprofile.
In the end, these steps resolved the issue:
brew uninstall python
pip3 install -U pyobjc
I tried to install a Python module by typing: sudo python setup.py install
After I typed this command I got a lot of output to the screen.
The lest few lines are bellow:
writing manifest file 'scikits.audiolab.egg-info/SOURCES.txt'
removing '/usr/lib/python2.5/site-packages/scikits.audiolab-0.10.2-py2.5.egg-info' (and everything under it)
Copying scikits.audiolab.egg-info to /usr/lib/python2.5/site-packages/scikits.audiolab-0.10.2-py2.5.egg-info
Installing /usr/lib/python2.5/site-packages/scikits.audiolab-0.10.2-py2.5-nspkg.pth
running install_scripts
So, there were nothing suspicious. But when I tried to use the module from the Python:
import pyaudiolab
I see that Python does not find the module:
Traceback (most recent call last):
File "test.py", line 1, in <module>
import pyaudiolab ImportError: No module named pyaudiolab
How can I found out what went wrong? As a result of the installation I get a new directory:
/usr/lib/python2.5/site-packages (so something happened) but I still cannot use the module. Can anybody help me with that?
Have you tried import scikits.audiolab or import audiolab?
From the OP's comment to an answer, it's clear that scikits.audiolab is indeed where this module's been installed, but it also needs you to install numpy. Assuming the module's configuration files are correct, by using easy_install instead of the usual python setup.py run, you might have automatically gotten and installed such extra dependencies -- that's one of the main points of easy_install after all. But you can also do it "manually" (for better control of where you get dependencies from and exactly how you install them), of course -- however, in that case, you do need to check and manually install the dependencies, too.
Your library depends upon numoy. Try installing numpy:
sudo apt-get install python-numpy
You need a more recent version of numpy (>= 1.2.0), as indicated on the audiolab installation informations.
check if you have the module somewhere inside:
/usr/lib/python2.5/site-packages/
(search for a file named |modulename|.py so in your example - try: pyaudiolab.py or audiolab.py)
if it exists - check if the directory in which it exists is found in the sys.path variable:
import sys
sys.path