bzr: ERROR: Couldn't import bzrlib and dependencies. Please check the directory containing bzrlib is on your PYTHONPATH. Traceback (most recent call last): File "/usr/local/bin/bzr", line 102, in <module> import bzrlib ImportError: No module named bzrlib

Bug #731391 reported by Jose Carlos Tejera Gonzalez
28
This bug affects 5 people
Affects Status Importance Assigned to Milestone
Bazaar Mac Installers
Fix Released
Medium
Gordon Tyler

Bug Description

I always get this error:

bzr: ERROR: Couldn't import bzrlib and dependencies.
Please check the directory containing bzrlib is on your PYTHONPATH.

Traceback (most recent call last):
  File "/usr/local/bin/bzr", line 102, in <module>
    import bzrlib
ImportError: No module named bzrlib

Revision history for this message
Jelmer Vernooij (jelmer) wrote : Re: [Bug 731391] [NEW] bzr: ERROR: Couldn't import bzrlib and dependencies. Please check the directory containing bzrlib is on your PYTHONPATH. Traceback (most recent call last): File "/usr/local/bin/bzr", line 102, in <module> import bzrlib ImportError: No module named bzrlib

On Tue, 2011-03-08 at 15:35 +0000, Jose Carlos Tejera Gonzalez wrote:
> Public bug reported:
>
> I always get this error:
>
> bzr: ERROR: Couldn't import bzrlib and dependencies.
> Please check the directory containing bzrlib is on your PYTHONPATH.
>
> Traceback (most recent call last):
> File "/usr/local/bin/bzr", line 102, in <module>
> import bzrlib
> ImportError: No module named bzrlib
How did you install bzr?

Cheers,

Jelmer

Revision history for this message
Vincent Ladeuil (vila) wrote :

What OS/bzr versions are you using and how did you install bzr ?

Changed in bzr:
status: New → Incomplete
Revision history for this message
Jose Carlos Tejera Gonzalez (jtejeraglez-deactivatedaccount) wrote :

I installed it in Mac OS X Lion and i downloaded the last stable version of bzr ( 2.2.2 ), i installed it with the installer

Vincent Ladeuil (vila)
affects: bzr → bzr-mac-installers
Revision history for this message
Vincent Ladeuil (vila) wrote :

The last stable version is 2.3.0, could you re-try with it ?

I kind of remember someone mentioning some incompatibility with Lion but nothing clear enough to investigate at the time (and I don't have an OSX host to play with these days).

The issue here may be that the installer thought you used one python version but your env says otherwise. So you find the script in /usr/local/bin but the installer put the bzrlib in another python version libraries.

One workaround would be to change the bang line in the script to use the expected python version but it's hard to describe precisely without seeing your setup and not being able to look at a working one :-/

Does Lion provides mulltiple pythons ? What does 'python -V' says in your case ?

Revision history for this message
Glen Ihrig (glen-arkadias) wrote :

I got the same error when I installed on OS X 10.5 using the 10.6 installer. My guess is that the problem is due to differing versions of Python between versions of OS X. (10.5 defaults to 2.5, 10.6 defaults to 2.6 - I'm guessing 10.7 defaults to 2.7).

The solution is as indicated in the error. Add the following to your ~/.profile

export PYTHONPATH="usr/local/bin/bzr:${PYTHONPATH}"

In my case that eliminated the error in this title, and Bazaar will function, but will be slow due to an inability to load compiled extensions (which were compiled for OS X 10.6) see: https://bugs.launchpad.net/bugs/733121

This 'fix' won't be necessary for an installation made with a proper installer compiled under OS X 10.7.

Revision history for this message
Manfred Bergmann (mdbergmann) wrote :

I'm getting the same error however only on push operations. commit, add, etc. works fine.
Tested wit a clean 2.3.1 install on Mac OS X 10.6.7.
Python version 2.6.1 (system).

Exporting PYTHONPATH as mentioned earlier doesn't fix it.

Manfred

Revision history for this message
Cyril Doussin (cdoussin) wrote :

This won't fix the bug in itself, but as a workaround, if you edit /usr/local/bin/bzr and change the first line to use python 2.6, the problem seems to be fixed. I've been able to bind, update and commit using this.

$sudo vi /usr/local/bin/bzr
then replace
#!/usr/bin/python
by
#!/usr/bin/python2.6

So it would appear that the installer is indeed detecting and using python 2.6 instead of the default 2.7.1 on Lion.

Revision history for this message
James Newell (jameslnewell) wrote :

I have the same problem on Mac OS X 10.7 installed from Bazaar-2.3.3-OSX-10.6-2.dmg.

Comment #7 by cdoussin resolves the problem for me too.

Revision history for this message
Garen Torikian (gjtorikian) wrote :

I'd like to chime in that Cyril's fix also worked for me on Lion.

Revision history for this message
GRiker (griker-deactivatedaccount) wrote :

I had the same problem after upgrading to Lion. After reinstalling 2.3.3 and editing the bzr file to point to python2.6, it now works again.

G

Revision history for this message
Mark Grandi (markgrandi) wrote :

I had this problem and i followed the instructions in comment #7 and it works now!

Jelmer Vernooij (jelmer)
Changed in bzr-mac-installers:
status: Incomplete → Confirmed
Revision history for this message
Mathias Feitzinger (k-mathias) wrote :

Thank you, Cyril Doussin (cdoussin). I have the same error under Mac OSX Lion and your post resolves my problem.

Revision history for this message
Fabio Ruini (fabio-ruini-n) wrote :

Same here using version 2.4b5 on Lion. Fixed following the advise in comment #7.

Revision history for this message
Connac (e-cb-t) wrote :

 Hi - I want to do as Cyril suggests but can't due to being the newest newbie ever. (started yesterday)

This is the first time I've tried anything like this - there seems to be assumed knowledge on even the simplest pages, and it looks like that's what I'm missing.

"then replace" is probably really simple for everyone else, but I can see the line where I need to add "2.6" and I can't type on it, and have no idea what else I can use to open that file and replace the text. I did the Sudo bit in Terminal on my Mac running OSx Lion and got to see what looked like a header of a file rather than any code I'd recognise as a script.

Happy to keep learning, but googling and searching this forum has come to a dead end for me. The learning curve from zero feels a bit vertical at the moment!

Can anyone help out? (when you've ceased chuckling)

Cheers

Revision history for this message
Connac (e-cb-t) wrote :

Me again - I have at last managed to edit the thing, but don't know where to save it, as I assume I need to otherwise the changes will be lost?

Tried after having saved to Documents and into the bar download folder but that's read only....

Revision history for this message
Stephen Rasku (ubuntu-srasku) wrote :

Connac, you need to edit in place. Simply save it over top of the original location. For me it's /usr/local/bin/bzr.

Revision history for this message
Stephen Rasku (ubuntu-srasku) wrote :

Also, you may want to backup the original first in case you really screw it up. Good luck.

Revision history for this message
Connac (e-cb-t) wrote :

Thanks Stephen. I'm now trying to save the wretched thing, which I've guessed is cmd + S, giving me the save as. I put in the path, press go and it then tells me I don't have rights.

It recommends I Find it in Finder - File and change the permissions, but no joy there either.

Slow route to the horizon....

Revision history for this message
Stephen Rasku (ubuntu-srasku) wrote :

What are you using to edit it. If you are calling the editor from the command line you can prepend it with "sudo". E.g.

    sudo vi /usr/local/bin/bzr

If you aren't editing from the command line then I would copy the file to a location where you can save it and the copy it back from the command line using

   sudo cp localfile /usr/loccal/bin/bzr

I assume you are an administrator on your computer. If you're not none of this is going to work.

Revision history for this message
Connac (e-cb-t) wrote :

Thanks again -

Using Terminal in Mac - am administrator. That's command line isn't it?

Have done the

sudo vi /usr/local/bin/bzr. That gave me what I thought was the file, with the line at the top,

#!/usr/bin/python

Which by determined use of delete, cursor keys and retyping, I changed to

#!/usr/bin/python2.6

At that stage, I had pretty much lost the command line - unless it can be used further up the page? But I thought the next command would have to go after the file I'd just edited. In any case, searching Linux for Dummies, I still can't see a save command equivalent to 'cp'

If I did the above, went back to the command line up the terminal page and typed 'sudo cp localfile /usr/local/bin/bzr' would that overwrite the file, without it complaining that I don't have rights? Sounds tantalisingly like it would.

Sorry about this - must be rather trying. If this doesn't work I'll leave you alone and go find the shallow end. It's my last post (cue music). Thanks very much.

Revision history for this message
Gordon Tyler (doxxx) wrote :

Connac, try using 'pico' to edit the file instead. So it would be:

    sudo pico /usr/loca/bin/bzr

Vi is not for the command-line newbie, it's pretty arcane. Pico should be easier to use, I hope.

Otherwise, do the following in your home directory:

1. cp /usr/local/bin/bzr bzr
2. Edit the 'bzr' file in your home directory with Text Editor or a similar plain text editor and change the first line as described above.
3. Save that file.
4. sudo cp bzr /usr/local/bin/bzr

Gordon Tyler (doxxx)
Changed in bzr-mac-installers:
assignee: nobody → Gordon Tyler (doxxx)
importance: Undecided → Medium
Revision history for this message
Gordon Tyler (doxxx) wrote :

I believe this should be fixed in the 2.5b4-2 installer. It should now explicitly use python 2.6 and ignores whatever python is on the PATH. Please let me know if it works for you.

Changed in bzr-mac-installers:
status: Confirmed → Fix Released
Revision history for this message
Stephen Rasku (ubuntu-srasku) wrote :

Confirmed that 2.5b4-2 installer works.

Revision history for this message
Rocrail (r.j.versluis) wrote :

I got the same problem when using the Bazaar-2.6.0-OSX-10.6-2.dmg on OS X 10.9 Mavericks.

bzr: ERROR: Couldn't import bzrlib and dependencies.
Please check the directory containing bzrlib is on your PYTHONPATH.

Traceback (most recent call last):
  File "/usr/local/bin/bzr", line 74, in <module>
    import bzrlib
ImportError: No module named bzrlib

Revision history for this message
Gordon Tyler (doxxx) wrote :

The default python since OS X 10.7 has been python 2.7 but the bzr installer for 10.6 is compiled against python 2.6. However, the installed /usr/local/bin/bzr script just references /usr/local/bin/python instead of python2.6, hence the problem on OS X 10.7 or newer.

As a workaround edit the /usr.local/bin/bzr script file and change the first line to reference /usr/local/bin/python2.6 instead.

Revision history for this message
Gordon Tyler (doxxx) wrote :

Typo in the last paragraph: it should be /usr/local/bin/bzr that is edited.

Revision history for this message
Gordon Tyler (doxxx) wrote :

And another typo in that last paragraph: it should be /usr/bin/python2.6 that is referenced in the first line of the bzr script.

Revision history for this message
Rocrail (r.j.versluis) wrote :

OK, works. :)

Revision history for this message
Brendan Simon (brendan-simon) wrote :

I just installed Bazaar-2.6.0-OSX-10.6-2.dmg on El Capitan and had the same issue. Changing the hash-bang line in the bzr app fixes the issue.

Would be nice if someone could do a small update with a new installer build so that the bzr will work out of the box when using the installer.

Revision history for this message
kiki (montecristo0) wrote :

Ths, It work.

$sudo vi /usr/local/bin/bzr
then replace
#!/usr/bin/python
by
#!/usr/bin/python2.6

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers