Skip to content

pip install problem - owner of .astropy is root - #867

Merged
embray merged 3 commits into
astropy:masterfrom
embray:issue-867
Apr 2, 2013
Merged

embray merged 3 commits into
astropy:masterfrom
embray:issue-867

Conversation

@embray

@embray embray commented Mar 28, 2013

Copy link
Copy Markdown
Member

I installed astropy with pip:
sudo pip install astropy
which seemed ok.

but when importing astropy:

In [1]: import astropy
/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/astropy/logger.py:524: RuntimeWarning: log file u'/Users/destry/.astropy/config/astropy.log' could not be opened for writing: [Errno 13] Permission denied: u'/Users/destry/.astropy/config/astropy.log'
  '{1}'.format(log_file_path, unicode(e)), RuntimeWarning)
Custom TB Handler failed, unregistering
---------------------------------------------------------------------------
SystemError                               Traceback (most recent call last)
/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/astropy/logger.pyc in ipy_exc_handler(ipyshell, etype, evalue, tb, tb_offset)
    304             def ipy_exc_handler(ipyshell, etype, evalue, tb, tb_offset=None):
    305                 # First use our excepthook

--> 306                 self._excepthook(etype, evalue, tb)
    307 
    308                 # Now also do IPython's traceback


/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/astropy/logger.pyc in _excepthook(self, etype, value, traceback)
    252 
    253         if mod is not None:
--> 254             self.error(message, extra={'origin': mod.__name__})
    255         else:
    256             self.error(message)

/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/logging/__init__.pyc in error(self, msg, *args, **kwargs)
   1156         """
   1157         if self.isEnabledFor(ERROR):
-> 1158             self._log(ERROR, msg, args, **kwargs)
   1159 
   1160     def exception(self, msg, *args):

/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/logging/__init__.pyc in _log(self, level, msg, args, exc_info, extra)
   1248                 exc_info = sys.exc_info()
   1249         record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
-> 1250         self.handle(record)
   1251 
   1252     def handle(self, record):

/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/logging/__init__.pyc in handle(self, record)
   1258         """
   1259         if (not self.disabled) and self.filter(record):
-> 1260             self.callHandlers(record)
   1261 
   1262     def addHandler(self, hdlr):

/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/logging/__init__.pyc in callHandlers(self, record)
   1298                 found = found + 1
   1299                 if record.levelno >= hdlr.level:
-> 1300                     hdlr.handle(record)
   1301             if not c.propagate:
   1302                 c = None    #break out

/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/logging/__init__.pyc in handle(self, record)
    742             self.acquire()
    743             try:
--> 744                 self.emit(record)
    745             finally:
    746                 self.release()

/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/astropy/logger.pyc in _stream_formatter(self, record)
    371             color_print(record.levelname, 'brown', end='')
    372         else:
--> 373             color_print(record.levelname, 'red', end='')
    374         print(": " + record.msg + " [{0:s}]".format(record.origin))
    375 

/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/astropy/utils/console.pyc in color_print(*args, **kwargs)
    136 
    137     write = file.write
--> 138     if isatty(file) and USE_COLOR():
    139         for i in xrange(0, len(args), 2):
    140             msg = args[i]

/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/astropy/config/configuration.pyc in __call__(self)
    316 
    317         #get the value from the relevant `configobj.ConfigObj` object

--> 318         sec = get_config(self.module)
    319         if self.name not in sec:
    320             self.set(self.defaultvalue)

/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/astropy/config/configuration.pyc in get_config(packageormod, reload)
    382 
    383     from .paths import get_config_dir
--> 384     from ..utils import find_current_module
    385 
    386     if packageormod is None:

SystemError: Parent module 'astropy' not loaded, cannot perform relative import
The original exception:

Changing the owner from root to my username for /Users/username/.astropy/ seems to have fixed the problem.

I'm using python2.7.2 from enthought, numpy 1.7, and I'm on a mac 10.8.2

@astrofrog

Copy link
Copy Markdown
Member

I've heard this from several other users, so I can confirm this is indeed something that we should fix.

@embray

embray commented Mar 12, 2013

Copy link
Copy Markdown
Member

I thought the .astropy directory wasn't created at install time. Or is it that if it already exists the installer will write a log file into it?

@mwcraig

mwcraig commented Mar 16, 2013

Copy link
Copy Markdown
Member

My experience might help with debugging:

I had this happen on one of my computers but not the other, both running OSX 10.8.2, same python distribution, etc.

The problem came up only on the computer where I accidentally did pip install astropy (without the sudo)--that failed, then I reinstalled with sudo pip install astropy and got the error described in this issue.

@embray

embray commented Mar 28, 2013

Copy link
Copy Markdown
Member

I tested this out, and after completely deleting my ~/.astropy and doing a pip install astropy in a virtualenv I am left with a new ~/.astropy/config/astropy.log file containing just:

'2013-03-28 16:46:27,608', 'astropy.sphinx.conf', 'WARNING', u"matplotlib's plot_directive could not be imported. Inline plots will not be included in the output"

Installing with pip should be result in anything being written to my home directory.

@embray

embray commented Mar 28, 2013

Copy link
Copy Markdown
Member

Note: This is not just an issue with pip. Running setup.py install from a source checkout also creates ~/.astropy. That's not really a problem for developers, but it shouldn't do that for users/packagers.

@embray

embray commented Mar 28, 2013

Copy link
Copy Markdown
Member

Could someone give the above fix a try? The pip end of things can be tested by running setup.py sdist and then pip install dist/astropy-0.3.<somethingsomething>.tar.gz

@mdboom

mdboom commented Mar 29, 2013

Copy link
Copy Markdown
Contributor

I particularly like the fact that this PR raises exceptions if C extensions can't be found and we're not in setup mode. We need to do that in any case.

I tried this out. I did the following:

>rm -rf ~/.astropy
# Delete previous installations of astropy, just to be sure
>rm -rf ~/python/lib64/python2.7/site-packages/astropy*
>git fetch iguananaut
>git checkout iguananaut/issue-867 
>git clean -fxd
>python setup.py sdist
>pip install dist/astropy-0.3.dev3601.tar.gz 
>ls -ld ~/.astropy
ls: cannot access /home/mdboom/.astropy: No such file or directory

# With master, I was getting a directory created, so I think this means it's working

@embray

embray commented Mar 29, 2013

Copy link
Copy Markdown
Member

Indeed--if you wanted you could even log more helpful errors if a C extension fails to import for some reason. But that's not really related to this issue.

@embray

embray commented Mar 29, 2013

Copy link
Copy Markdown
Member

Apparently this is blowing up for Python 3.x. I didn't realized that the astropy.wcs.wcs module was pure Python. In fact, it's designed to still be importable even if the C module isn't importable. So does wcs really needs this check in wcs.__init__, @mdboom?

@embray

embray commented Mar 29, 2013

Copy link
Copy Markdown
Member

For what it's worth it seems to work if I change the except statement in wcs.__init__ to except (ImportError, SyntaxError), but I don't know how I feel about that.

Comment thread astropy/__init__.py

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not understanding how you're getting away from using this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch isn't even reached if _ASTROPY_SETUP_ == True. In https://github.com/astropy/astropy/pull/867/files#L5R567 I changed the astropy.cfg generation to still behave as though it's running in "SETUP" mode (which really, it is). But that's what also necessitated changes like https://github.com/astropy/astropy/pull/867/files#L3R15. Now when the generate_config runs, those imports will succeed. They're always attempted, but only allowed to fail if not in "SETUP" mode (where it's possible for them to fail if the extension modules haven't been built yet).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I get it now. That seems cleaner anyway.

embray added 2 commits April 2, 2013 11:41
setup.py install (and in particular when installing Astropy with pip)
the ~/.astropy directory gets generated, when really it shouldn't be.
This commit does a few different things:

 * I've never been too thrilled about having code that can modify the
   system at import time. In the case of generating the default
   astropy.cfg and log I think we have a reasonable excuse, but let's
   try to keep stuff like that in astropy/__init__.py: For that reason I
   moved the logger module initialization code to an `_init_log()`
   function which is called in ``astropy.__init__``.  I also set up a
   default dummy-log so that stuff like ``from astropy import log`` will
   always work even if the real logger hasn't been initialized.

 * For the default config generation I got rid of the environment
   variable hack and just set ``_ASTROPY_SETUP_`` when running the
   subprocess.

   * This requires changing the imports that are only performed when
    ``not _ASTROPY_SETUP_`` to be at least attempted, and only raise an
    exception if we're not in setup mode (this way when the default
    config generator gets to those imports they will still work).

 * Ensured that no attempt is made to create a config file if
   ``_ASTROPY_SETUP_``.
…o through much of astropy.io.fits and make it at least *importable* under Python 3, since the only places the wcs module was having issues was where it imports from io.fits.
@embray

embray commented Apr 2, 2013

Copy link
Copy Markdown
Member

Rerunning the Travis build for this because it blew up for weird reasons.

…make in Astropy than in pyfits, which still supports Python 2.5
@embray

embray commented Apr 2, 2013

Copy link
Copy Markdown
Member

Great well I think this should be fixed now, but will Travis ever run the tests?

@embray

embray commented Apr 2, 2013

Copy link
Copy Markdown
Member

Okay, travis passed except for the build_sphinx test again. I'll go ahead and merge this.

embray added a commit that referenced this pull request Apr 2, 2013
pip install problem - owner of .astropy is root
@embray
embray merged commit 4bd4d21 into astropy:master Apr 2, 2013
@embray
embray deleted the issue-867 branch April 2, 2013 21:45
@eteq

eteq commented Apr 3, 2013

Copy link
Copy Markdown
Member

@mwcraig @astrofrog @destrys - can you see if these changes fixed the problem for you? (this has been merged, so you can use master, or the 0.2.1 version @iguananaut will put out very soon)

I ask mainly because there are other ways ~/.astropy might accidentally be getting created, so it would be good to be sure the problem fixed here wasn't just masking another one.

embray added a commit that referenced this pull request Apr 3, 2013
embray added a commit that referenced this pull request Apr 3, 2013
pip install problem - owner of .astropy is root
Conflicts:

	astropy/utils/timer.py
embray added a commit that referenced this pull request Apr 3, 2013
@mwcraig

mwcraig commented Apr 4, 2013

Copy link
Copy Markdown
Member

0.2.1 worked for me, thanks!

@embray

embray commented Apr 4, 2013

Copy link
Copy Markdown
Member

😌💨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants