PyPM cannot "open database file None None" !

Posted by eric.38.fr on 2011-05-24 03:53

I just wanted to install a Python env. on an "old" Windows XP (SP3) PC ; I used "ActivePython-2.7.1.4-win32-x86.msi" with all standard options.

When finished (no reported problem or even warning), I wanted to add a few packages. Therefore, I ran PyPM. It's version 1.3.1. But :

> pypm info
error: (OperationalError) unable to open database file None None

Can someone give me a beginning of a clue to deal with and fix this ?

Thanks in advance
-- Éric

sridharr | Tue, 2011-05-31 09:20

Could you paste the output of pypm -v info? The "-v" option shows you the full traceback.

You could also recreate the database cache by running pypm sync -f for a possible immediate fix.

eric.38.fr | Wed, 2011-07-27 01:38

| You could also recreate the database cache by running pypm sync -f
| for a possible immediate fix.

No better result :

> pypm sync -f
error: (OperationalError) unable to open database file None None

Here is the result of a pypm -v info :

> pypm -v info
error: (OperationalError) unable to open database file None None
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\pypm\external\applib\log.py", line 87, in __run_safely
    yield
  File "C:\Python27\lib\site-packages\pypm\external\applib\log.py", line 78, in bootstrapped
    self.initialize()
  File "C:\Python27\lib\site-packages\pypm\client\command.py", line 195, in initialize
    force=self.options.force,
  File "C:\Python27\lib\site-packages\pypm\client\base.py", line 116, in make_pypm_environment2
    pyenv=pyenv, **kwargs)
  File "C:\Python27\lib\site-packages\pypm\client\base.py", line 76, in __init__
    P.join(self.pypm_dir, 'installed.db')
  File "C:\Python27\lib\site-packages\pypm\client\store.py", line 164, in __init__
    self._db = InstalledPackageDatabase(self.storepath, touch=True)
  File "C:\Python27\lib\site-packages\pypm\external\applib\_simpledb.py", line 107, in __init__
    self.metadata.create_all(self.engine)
  File "C:\Python27\lib\site-packages\sqlalchemy\schema.py", line 2148, in create_all
    bind.create(self, checkfirst=checkfirst, tables=tables)
  File "C:\Python27\lib\site-packages\sqlalchemy\engine\base.py", line 1698, in create
    connection=connection, **kwargs)
  File "C:\Python27\lib\site-packages\sqlalchemy\engine\base.py", line 1735, in _run_visitor
    conn = self.contextual_connect(close_with_result=False)
  File "C:\Python27\lib\site-packages\sqlalchemy\engine\base.py", line 1829, in contextual_connect
    self.pool.connect(),
  File "C:\Python27\lib\site-packages\sqlalchemy\pool.py", line 191, in connect
    agent = _ConnectionFairy(self)
  File "C:\Python27\lib\site-packages\sqlalchemy\pool.py", line 369, in __init__
    rec = self._connection_record = pool.get()
  File "C:\Python27\lib\site-packages\sqlalchemy\pool.py", line 213, in get
    return self.do_get()
  File "C:\Python27\lib\site-packages\sqlalchemy\pool.py", line 599, in do_get
    c = self.create_connection()
  File "C:\Python27\lib\site-packages\sqlalchemy\pool.py", line 147, in create_connection
    return _ConnectionRecord(self)
  File "C:\Python27\lib\site-packages\sqlalchemy\pool.py", line 253, in __init__
    self.connection = self.__connect()
  File "C:\Python27\lib\site-packages\sqlalchemy\pool.py", line 319, in __connect
    connection = self.__pool._creator()
  File "C:\Python27\lib\site-packages\sqlalchemy\engine\strategies.py", line 82, in connect
    return dialect.connect(*cargs, **cparams)
  File "C:\Python27\lib\site-packages\sqlalchemy\engine\default.py", line 249, in connect
    return self.dbapi.connect(*cargs, **cparams)
OperationalError: (OperationalError) unable to open database file None None

-- Eric, a bit disappointed

sridharr | Wed, 2011-07-27 10:16

Try deleting this directory C:\Documents and Settings\<username>\Local Settings\Application Data\ActiveState\PyPM (be sure to substitute your "username") and see if that fixes the issue. I wonder if the above error is due to the current user having no write access to this directory.

The file being referred to in that error message ("unable to open database file") actually resides under this directory. The `-f` option to the sync command is supposed to recreate this file.

sridharr | Wed, 2011-07-27 10:17

BTW, you may want to upgrade to the recently released 2.7.2.5

eric.38.fr | Thu, 2011-07-28 02:52

Thanks for your advice. But nope, deleting this directory did not fix it. It recreated it, with a bunch of embedded directories, and a sole "PyPM.log" file at one end of the two branches.

I'll do upgrade, and see if it makes it...
-- [edit] No, it didn't :(

sridharr | Thu, 2011-07-28 14:40

My previous comment was in error. I meant to delete the directory %APPDATA%\Python\Python27\site-packages\_pypm (take a backup first!) as the traceback above shows a problem with the "installed.db" file under this directory. After you delete this directory, run the normal `pypm` commands.

#

If that doesn't fix the problem, read on ....

1. 2.7.2.5 includes sqlalchemy in a private area (pypm/external/2/). So, after the upgrade, make sure that the directory C:\Python27\lib\site-packages\sqlalchemy is deleted. (Alternatively, you can uninstall first, remove all of C:\Python27 and install again)

2. Run and paste the output of pypm -v info

3. At the end of the traceback (above), note the file path for sqlalchemy\engine\default.py; edit that file at the specified line (where original error occurred) to insert a print statement like this:

    def connect(self, *cargs, **cparams):
        print("SQLAlchemy connect: (%s, %s)" % (cargs, cparams))
        return self.dbapi.connect(*cargs, **cparams)

4. Run pypm -v info again, and tell me what that print statement printed.

5. Finally, please send the "installed.db" file (created under "%APPDATA%\Python\Python27\site-packages\_pypm") to sridharr@activestate.com (or preferably as a bug in bugs.activestate.com)

lazymf | Thu, 2011-10-13 23:38

Hello.

I have the same problem as Eric, but under Windows 7 (ActivePython 2.7.2.5). In my case, it manifests itself only in cases where the user name contains Cyrillic characters.
I added the line you specify to a file sqlalchemy\engine\default.py. When I try to run 'pypm -v info' I get this:

C:\>pypm -v info
SQLAlchemy connect: (('C:\\Users\\\xd2\xe5\xf1\xf2\xee\xe2\xfb\xe9\\AppData\\Roaming\\Python\\Python27\\site-packages\\_pypm\\installed.db',), {})
error: (OperationalError) unable to open database file None None
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\pypm\external\applib\log.py", line 87, in __run_safely
yield
File "C:\Python27\lib\site-packages\pypm\external\applib\log.py", line 78, in bootstrapped
self.initialize()
File "C:\Python27\lib\site-packages\pypm\client\command.py", line 193, in initialize
force=self.options.force,
File "C:\Python27\lib\site-packages\pypm\client\base.py", line 114, in make_pypm_environment2
pyenv=pyenv, **kwargs)
File "C:\Python27\lib\site-packages\pypm\client\base.py", line 74, in __init__
P.join(self.pypm_dir, 'installed.db')
File "C:\Python27\lib\site-packages\pypm\client\store.py", line 163, in __init__
self._db = InstalledPackageDatabase(self.storepath, touch=True)
File "C:\Python27\lib\site-packages\pypm\external\applib\_simpledb.py", line 107, in __init__
self.metadata.create_all(self.engine)
File "C:\Python27\lib\site-packages\pypm\external\2\sqlalchemy\schema.py", line 2148, in create_all
bind.create(self, checkfirst=checkfirst, tables=tables)
File "C:\Python27\lib\site-packages\pypm\external\2\sqlalchemy\engine\base.py", line 1698, in create
connection=connection, **kwargs)
File "C:\Python27\lib\site-packages\pypm\external\2\sqlalchemy\engine\base.py", line 1735, in _run_visitor
conn = self.contextual_connect(close_with_result=False)
File "C:\Python27\lib\site-packages\pypm\external\2\sqlalchemy\engine\base.py", line 1829, in contextual_connect
self.pool.connect(),
File "C:\Python27\lib\site-packages\pypm\external\2\sqlalchemy\pool.py", line 191, in connect
agent = _ConnectionFairy(self)
File "C:\Python27\lib\site-packages\pypm\external\2\sqlalchemy\pool.py", line 369, in __init__
rec = self._connection_record = pool.get()
File "C:\Python27\lib\site-packages\pypm\external\2\sqlalchemy\pool.py", line 213, in get
return self.do_get()
File "C:\Python27\lib\site-packages\pypm\external\2\sqlalchemy\pool.py", line 599, in do_get
c = self.create_connection()
File "C:\Python27\lib\site-packages\pypm\external\2\sqlalchemy\pool.py", line 147, in create_connection
return _ConnectionRecord(self)
File "C:\Python27\lib\site-packages\pypm\external\2\sqlalchemy\pool.py", line 253, in __init__
self.connection = self.__connect()
File "C:\Python27\lib\site-packages\pypm\external\2\sqlalchemy\pool.py", line 319, in __connect
connection = self.__pool._creator()
File "C:\Python27\lib\site-packages\pypm\external\2\sqlalchemy\engine\strategies.py", line 82, in connect
return dialect.connect(*cargs, **cparams)
File "C:\Python27\lib\site-packages\pypm\external\2\sqlalchemy\engine\default.py", line 250, in connect
return self.dbapi.connect(*cargs, **cparams)
OperationalError: (OperationalError) unable to open database file None None

The real name of the folder %APPDATA%:

C:\>cd %APPDATA%
C:\Users\????????\AppData\Roaming>

My guess is that Eric uses the letter É in the name of his account - and it breaks sqlalchemy as well as in my case Cyrillic letters.

As a workaround I switched to using an account with Latin letters in its name. After that everything works just fine.

>>
lazymf | Thu, 2011-10-13 23:43

>> C:\Users\????????\AppData\Roaming>

It seems the forum does not support the Russian alphabet too :)

atento | Fri, 2014-09-05 11:20

1. The problem with non-ASCII Windows username is still exists with fresh x86 Python
2. The workaround is to use GLOBAL install database with -g option:
pypm -g install oauth2