开发者

Python and Ubuntu file not found

I have been running several versions of Python on my Ubuntu 10.10 for a while but I was having some issues with python2.5 (for Google app-engine) So I blew the 2.5 install away(and removed the site-packages directory along with the Python2.5 directory) and re-installed... got the same error,, a file not found that was there.. so I figured I try to install Virtual env and work with that. well now it seems that all of my pythons are hosed..

I cannot execute a py file from the command line eg. "python python.py" and this is the case for all the versions I have.. so I'm wondering if there is some global setting that got hosed?? don't have a clue where to look.. The example below shows that the virtualenv file can be imported but cannot be executed as normal, just gets a not found.. I did change permissions to execute on the virtualenv.py file but that made no difference. I have virtualenv installed on several versions of Python, 2.6, 2.7 (in addition to 2.5) and I'm getting the same behavior on all so I suspect Bash or something in Ubuntu, not python not virtual env..

enter code here
tom@tom-Satellite-A105:~$ pyth开发者_StackOverflowon2.5 virtualenv.py env
python2.5: can't open file 'virtualenv.py': [Errno 2] No such file or directory
tom@tom-Satellite-A105:~$ python2.5
Python 2.5.6 (r256:88840, Aug  6 2011, 08:40:44) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> import virtualenv
>>> exit()

^^^^^^ shows that Python2.5 can import virtualenv fine In the meantime starting up my alternate machine :-(


When you import it, it goes through the Python path to find it, but when you enter:

python2.5 virtualenv.py

that assumes it's in the current directory.


A good starting point for tracing such WTF's is to run the process under strace which will report (copiously) the system calls made and the results of each... you can then see if it's really the file that can't be found, or some other issue

$ trace python NOFILE.py
execve("/usr/bin/python", ["python", "NOFILE.py"], [/* 63 vars */]) = 0
brk(0)                                  = 0x9bef000
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb78de000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=160388, ...}) = 0
mmap2(NULL, 160388, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb78b6000
close(3)                                = 0
  ...[snip]...
stat64("NOFILE.py", 0xbfbc53bc)         = -1 ENOENT (No such file or directory)
stat64("NOFILE.py", 0xbfbc53cc)         = -1 ENOENT (No such file or directory)
open("NOFILE.py", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
write(2, "/usr/bin/python2.6: can't open f"..., 85/usr/bin/python2.6: can't open file 'NOFILE.py': [Errno 2] No such file or directory) = 85
exit_group(2)                           = ?

For example strace invoking python with your script, a script that DOES open, and a non-existent file, and then diff the traces.... my guess is you'll find the error is elsewhere but that the error is reported wrong

If virtualenv.py is not in the local folder, you could try explicitly setting PYTHONPATH to see if that fixes it (see "python -h") and if so, then have a look at what's modifying sys.path on a setup where it does work (eg run strace again)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜