How to import different version of SQLachlemy?

56 views
Skip to first unread message

Ning

unread,
Dec 8, 2009, 6:00:28 PM12/8/09
to sqlalchemy
Hello

I am new to python. I have got two version of SQLAlchemy, 0.4.0 and
5.5.

Some of my old script built in 0.4.0, and I do not want to change the
script.

Is that any way I can define in the script to use SQLAlchemy 0.3.11
for my old script and 5.5 for my new script?

I think you can use pkgresources to determine which version of
sqlalchemy to be imported. but it is not working, please see my code
below:

In [23]: from pkg_resources import require
In [24]: require('sqlalchemy == 0.4.0')
Out[24]: [sqlalchemy 0.4.0 (c:\pythonxy\python26\lib\site-packages
\sqlalchemy-0.4.0-py2.6.egg)]
In [25]: import sqlalchemy
In [26]: sqlal
sqlalchemy sqlalchemy-0.4.0-py2.6.egg sqlalchemy-0.5.6-py2.6.egg
In [26]: sqlalchemy.__version__
Out[26]: '0.4.0'

That is file, but when i try to load version 5.6. It said got version
conflict

In [28]: require('sqlalchemy == 0.5.6')
---------------------------------------------------------------------------
VersionConflict Traceback (most recent call last)

C:\Pythonxy\Python26\Lib\site-packages\<ipython console> in <module>()

C:\Pythonxy\Python26\Lib\site-packages\pkg_resources.pyc in require
(self, *requirements)
624 """
625
--> 626 needed = self.resolve(parse_requirements(requirements))
627
628 for dist in needed:
C:\Pythonxy\Python26\Lib\site-packages\pkg_resources.pyc in resolve
(self, requirements, env, install
er)
526 if dist not in req:
527 # Oops, the "best" so far conflicts with a dependency
--> 528 raise VersionConflict(dist,req) # XXX put more info here
529 requirements.extend(dist.requires(req.extras)[::-1])
530 processed[req] = True
VersionConflict: (sqlalchemy 0.4.0 (c:\pythonxy\python26\lib\site-
packages\sqlalchemy-0.4.0-py2.6.egg), Requirement.parse
('sqlalchemy==0.5.6'))

any help will be more than welcome. :D

Ning

Philip Jenvey

unread,
Dec 8, 2009, 9:33:33 PM12/8/09
to sqlal...@googlegroups.com
To be able to switch between two versions of a package with pkg_resources.require you'll need to install both with the multi-version (-m) argument to easy_install.

--
Philip Jenvey

werner

unread,
Dec 9, 2009, 3:30:39 AM12/9/09
to sqlal...@googlegroups.com
Ning wrote:
> Hello
>
> I am new to python. I have got two version of SQLAlchemy, 0.4.0 and
> 5.5.
>
> Some of my old script built in 0.4.0, and I do not want to change the
> script.
>
> Is that any way I can define in the script to use SQLAlchemy 0.3.11
> for my old script and 5.5 for my new script?
>
>
I use this code:
if not hasattr(sys, 'frozen'):
import pkg_resources
pkg_resources.require("sqlalchemy") # get latest version
## pkg_resources.require("sqlalchemy==0.4.3") # use a specific version

Use the last line and set it to the version you want. I check for
"frozen" as a deploy with py2exe and this would not work for the
py2exe'd version.

Werner

Ning

unread,
Dec 9, 2009, 7:55:16 AM12/9/09
to sqlalchemy
thank so much!

It sloved the problem. I think the reason for my previous script not
working is because i try to import different package in one windows.

Thanks again for all of your help!

Ning
Reply all
Reply to author
Forward
0 new messages