Closed snim2 closed 12 years ago
Hi Sarah,
Sorry to hear that things aren't working. Can you verify that running python -c "from lib2to3.main import main"
from your shell works?
Yup, I get this:
$ python -c "from lib2to3.main import main"
Traceback (most recent call last):
File "
Hope that helps!
Sarah
Hmmm. That passes successfully on my machine (python 2.7.3 on OSX). Can you find where your python is installed, look in the lib2to3 folder, confim that there is a main.py file and look in the contents of that?
There should be something that looks like this:
85 def main(fixer_pkg, args=None):
86 """Main program.
87
88 Args:
89 fixer_pkg: the name of a package where the fixers are located.
90 args: optional; a list of command line arguments. If omitted,
91 sys.argv[1:] is used.
92
93 Returns a suggested exit status (0, 1, 2).
94 """
95 # Set up option parser
96 parser = optparse.OptionParser(usage="2to3 [options] file|dir ...")
97 parser.add_option("-d", "--doctests_only", action="store_true",
98 ...
Well, as it turns out I do have that file in /usr/lib/python2.7/lib2to3/ and it does have a function called main()
like the one you show above. However, I think the problem is that the main module itself cannot be imported, although the lib2to3 package can. Very odd.
That's unusual. I think the ImportError might be a red herring. Can you try this:
>>> import lib2to3.main
>>> main = lib2to3.main.main
I think this may give us a better error.
ImportError: No module named main.main
>>> dir(lib2to3.main)
AttributeError: 'module' has no attribute 'main'
how about import lib2to3; lib2to3.__file__
. Is it the same as the file you inspected to make sure it has the main()
method?
Ah.... this is very interesting:
$ python
Python 2.7.3 (default, Aug 1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import lib2to3
>>> lib2to3.__file__
'/usr/local/lib/python2.7/dist-packages/pythoscope-0.4.3-py2.7.egg/lib2to3/__init__.pyc'
>>>
}}}
So, I installed pythoscope site-wide and it looks like that has messed up lib2to3. I guess that means you can close this as an Issue in pep8ify. Any ideas how to fix it though?
Two ideas:
1.) Uninstall pythoscope if you don't need it. 2.) Either use pythoscope or pep8ify inside of a virtualenv.
You could also open an issue with pythoscope and ask them to rename the module. It's not really great practice to override the name of a standard lib module.
You could also try simply removing their copy of lib2to3, and/or replacing it with a link to your proper system-wide library.
We work really hard in the Django project to make sure that the libraries we do bundle never ever override the system libraries if they exist - this is the kind of problem that results if you don't have that kind of import logic.
Glad we got to the bottom of this. I certainly was puzzled.
I'm going to close this issue Sarah. Feel free to keep commenting if you need more help.
Many thanks all! I should really be using virtualenv, I keep putting it off, but this is a bit of an incentive!
This is the mirror bug report on the Pythoscope Launchpad:
I've tried installing pep8ify by PIP, easy_install and by cloning the git repo and using setup.py. Each time I get this error:
$ pep8ify test2.py Traceback (most recent call last): File "/usr/local/bin/pep8ify", line 9, in
load_entry_point('pep8ify==0.0.5', 'console_scripts', 'pep8ify')()
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 337, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2279, in load_entry_point
return ep.load()
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1989, in load
entry = import(self.module_name, globals(),globals(), ['name'])
File "/usr/local/lib/python2.7/dist-packages/pep8ify-0.0.5-py2.7.egg/pep8ify/pep8ify.py", line 6, in
from lib2to3.main import main
ImportError: No module named main
This is running Python 2.7.3 on Ubuntu Pangolin. The library lib2to3 is installed and I can import it from the interactive interpreter.