You are not logged in.

#1 2015-05-13 02:05:08

bigeast
Member
Registered: 2013-04-19
Posts: 9

Python's getpass module can't be imported

getpass is in the Python Standard Library, when I import it from the python prompt, an error occurs:

Python 3.4.3 (default, Mar 25 2015, 17:13:50) 
[GCC 4.9.2 20150304 (prerelease)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import getpass
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: bad magic number in 'getpass': b'\x03\xf3\r\n'
>>> 

I have checked that there is not *.pyc file in /usr/lib/python3.4.

What's wired is, it can be imported correctly and works fine in ipython, which use python3.4 as backend:

Python 3.4.3 (default, Mar 25 2015, 17:13:50) 
Type "copyright", "credits" or "license" for more information.

IPython 3.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import getpass

In [2]: getpass.unix_getpass()
Password: 

Same problem with python2 and ipython2

Offline

#2 2015-05-13 02:17:40

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: Python's getpass module can't be imported

Seems like you might have something funky in your installation (works fine here all around). Maybe try uninstalling/reinstalling python (could be easier said than done, depending on what programs you have that are dependent on it). Also check in /usr/local, /opt and ~/.local for any other python libraries you may have installed with easy_install or pip.

Scott

Offline

#3 2015-05-13 03:15:11

bigeast
Member
Registered: 2013-04-19
Posts: 9

Re: Python's getpass module can't be imported

firecat53 wrote:

Seems like you might have something funky in your installation (works fine here all around). Maybe try uninstalling/reinstalling python (could be easier said than done, depending on what programs you have that are dependent on it). Also check in /usr/local, /opt and ~/.local for any other python libraries you may have installed with easy_install or pip.

Scott

Thanks for your reply, Scott.

I used to install python libraries with

sudo pip install some-package

, so they are all in /usr/lib/python3.4/site-package. (Besides, I accidently rm -r ~/.local just now... but problem still here.)

I'm not willing to uninstall python for this little bug, for I'm not sure I can install all the things back.

So I can never know how many bugs is there until I meet them?

Offline

#4 2015-05-13 03:18:28

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,803

Re: Python's getpass module can't be imported

Why are you using pip install ?


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#5 2015-05-13 03:40:57

bigeast
Member
Registered: 2013-04-19
Posts: 9

Re: Python's getpass module can't be imported

ewaller wrote:

Why are you using pip install ?

Why not? You mean I should use easy_install?

Is there something wrong with pip? I thought it was a popular way to install python package.

Offline

#6 2015-05-13 03:46:17

bigeast
Member
Registered: 2013-04-19
Posts: 9

Re: Python's getpass module can't be imported

bigeast wrote:
ewaller wrote:

Why are you using pip install ?

Why not? You mean I should use easy_install?

Is there something wrong with pip? I thought it was a popular way to install python package.

Oh, or you think I should install from pacman, but I think pip install is also a good choice, and I'm not used to write PKGBUILD myself for python package when it's already available in pypi but not in pacman or aur.

Last edited by bigeast (2015-05-13 03:46:36)

Offline

#7 2015-05-13 03:52:19

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,803

Re: Python's getpass module can't be imported

In general, we recommend you let Pacman control what is installed in Arch Linux, otherwise you end up being on your own with no single point of reference as to what is installed where.  Every Python I have ever needed has been in the repositories or in the AUR.  Writing a PKGBUILD to build the package for you to install it with pacman is simple.

My system is about a month old after having worked with my old machine for many years.  I've not done any Python development on this still fresh system, but somehow it has all the packages in place I need with all the libraries accounted for and in the right place.  Your system has problems finding the parts you need -- they might be installed, but perhaps they are not where Python expects them.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#8 2015-05-13 03:54:03

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,803

Re: Python's getpass module can't be imported

bigeast wrote:

Oh, or you think I should install from pacman, but I think pip install is also a good choice, and I'm not used to write PKGBUILD myself for python package when it's already available in pypi but not in pacman or aur.

We were posting at the same time.  Well, if it works for you, great.  It is your system.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#9 2015-05-13 04:31:00

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: Python's getpass module can't be imported

If you use pip, typically only use it as a user (pip install --user), or inside a virtualenv. It's too easy to mess with system packages by using 'sudo pip install' or 'sudo easy_install' or 'sudo make install'. Make a PKGBUILD if you want to install something system-wide.

Scott

Offline

#10 2015-05-13 04:44:39

bigeast
Member
Registered: 2013-04-19
Posts: 9

Re: Python's getpass module can't be imported

ewaller wrote:
bigeast wrote:

Oh, or you think I should install from pacman, but I think pip install is also a good choice, and I'm not used to write PKGBUILD myself for python package when it's already available in pypi but not in pacman or aur.

We were posting at the same time.  Well, if it works for you, great.  It is your system.

Thanks for pointing out the better way using pacman. I'm a little lazy as an Arch user, but as you've mentioned, install software without pacman can cause potential problem, I think maybe it's time for me to use pacman more often.

Anyway, I don't want to meet annoying bugs like this anymore!

Now I'm wondering what if someday I'm working on a system that isn't Archlinux...

Offline

#11 2015-05-13 04:48:59

bigeast
Member
Registered: 2013-04-19
Posts: 9

Re: Python's getpass module can't be imported

firecat53 wrote:

If you use pip, typically only use it as a user (pip install --user), or inside a virtualenv. It's too easy to mess with system packages by using 'sudo pip install' or 'sudo easy_install' or 'sudo make install'. Make a PKGBUILD if you want to install something system-wide.

Scott

But for this problem, getpass is in standard library.

Maybe I should uninstall all the packages from pip, and then reinstall them by pacman to solve this little bug!

Offline

Board footer

Powered by FluxBB