[Tutor] attempting to install PIP

2014-11-24 Thread Paul LaBerge
Hello,

I’m trying to install PIP on a Mac running Yosemite. I downloaded get-pip.py 
from https://pip.pypa.io/en/latest/installing.html 
. I copied it to /usr/local/bin/ 
then  ran python get-pip.py. It repeatedly downloaded something up to a count 
of 100. From looking at the debug log it seems it was checking every version of 
PIP back to 0.2 before selecting version 1.5.6. 

Using version 1.5.6 (newest of versions: 1.5.6, 1.5.6, 0.2)


The result was:

snip

99  Downloading pip-1.5.6-py2.py3-none-any.whl (1.0MB): 100  Downloading 
pip-1.5.6-py2.py3-none-any.whl (1.0MB):  Downloading 
pip-1.5.6-py2.py3-none-any.whl (1.0MB): 1.0MB downloaded
Installing collected packages: pip
Cleaning up...
Exception:
Traceback (most recent call last):
  File 
"/var/folders/ft/pthcg_6j06zfdp0sl14kn76wgn/T/tmp6QIoTv/pip.zip/pip/basecommand.py",
 line 122, in main
status = self.run(options, args)
  File 
"/var/folders/ft/pthcg_6j06zfdp0sl14kn76wgn/T/tmp6QIoTv/pip.zip/pip/commands/install.py",
 line 283, in run
requirement_set.install(install_options, global_options, 
root=options.root_path)
  File 
"/var/folders/ft/pthcg_6j06zfdp0sl14kn76wgn/T/tmp6QIoTv/pip.zip/pip/req.py",
 line 1435, in install
requirement.install(install_options, global_options, *args, **kwargs)
  File 
"/var/folders/ft/pthcg_6j06zfdp0sl14kn76wgn/T/tmp6QIoTv/pip.zip/pip/req.py",
 line 671, in install
self.move_wheel_files(self.source_dir, root=root)
  File 
"/var/folders/ft/pthcg_6j06zfdp0sl14kn76wgn/T/tmp6QIoTv/pip.zip/pip/req.py",
 line 901, in move_wheel_files
pycompile=self.pycompile,
  File 
"/var/folders/ft/pthcg_6j06zfdp0sl14kn76wgn/T/tmp6QIoTv/pip.zip/pip/wheel.py",
 line 215, in move_wheel_files
clobber(source, lib_dir, True)
  File 
"/var/folders/ft/pthcg_6j06zfdp0sl14kn76wgn/T/tmp6QIoTv/pip.zip/pip/wheel.py",
 line 205, in clobber
os.makedirs(destdir)
  File 
"/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py",
 line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: 
'/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip'

Storing debug log for failure in /Users/PaulSan/.pip/pip.log


It seems that PIP was not installed because of the permission’s error. Any 
light that can be cast on what happened and what I should do next would be 
appreciated. 

thanks in advance,

Paul___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] attempting to install PIP

2014-11-24 Thread Albert-Jan Roskam

> From: Paul LaBerge 
>To: tutor@python.org 
>Sent: Monday, November 24, 2014 6:05 AM
>Subject: [Tutor] attempting to install PIP
> 
>
>
>Hello,
>I’m trying to install PIP on a Mac running Yosemite. I downloaded get-pip.py 
>from https://pip.pypa.io/en/latest/installing.html. I copied it to 
>/usr/local/bin/ then  ran python get-pip.py. It repeatedly downloaded 
>something up to a count of 100. From looking at the debug log it seems it was 
>checking every version of PIP back to 0.2 before selecting version 1.5.6. 
>Using version 1.5.6 (newest of versions: 1.5.6, 1.5.6, 0.2)
>
>
>The result was:
>snip
>99  Downloading pip-1.5.6-py2.py3-none-any.whl (1.0MB): 100  Downloading 
>pip-1.5.6-py2.py3-none-any.whl (1.0MB):  Downloading 
>pip-1.5.6-py2.py3-none-any.whl (1.0MB): 1.0MB downloaded
>Installing collected packages: pip
>Cleaning up...
>Exception:
>Traceback (most recent call last):
>  File 
> "/var/folders/ft/pthcg_6j06zfdp0sl14kn76wgn/T/tmp6QIoTv/pip.zip/pip/basecommand.py",
>  line 122, in main
>status = self.run(options, args)
>  File 
> "/var/folders/ft/pthcg_6j06zfdp0sl14kn76wgn/T/tmp6QIoTv/pip.zip/pip/commands/install.py",
>  line 283, in run
>requirement_set.install(install_options, global_options, 
> root=options.root_path)
>  File 
> "/var/folders/ft/pthcg_6j06zfdp0sl14kn76wgn/T/tmp6QIoTv/pip.zip/pip/req.py",
>  line 1435, in install
>requirement.install(install_options, global_options, *args, **kwargs)
>  File 
> "/var/folders/ft/pthcg_6j06zfdp0sl14kn76wgn/T/tmp6QIoTv/pip.zip/pip/req.py",
>  line 671, in install
>self.move_wheel_files(self.source_dir, root=root)
>  File 
> "/var/folders/ft/pthcg_6j06zfdp0sl14kn76wgn/T/tmp6QIoTv/pip.zip/pip/req.py",
>  line 901, in move_wheel_files
>pycompile=self.pycompile,
>  File 
> "/var/folders/ft/pthcg_6j06zfdp0sl14kn76wgn/T/tmp6QIoTv/pip.zip/pip/wheel.py",
>  line 215, in move_wheel_files
>clobber(source, lib_dir, True)
>  File 
> "/var/folders/ft/pthcg_6j06zfdp0sl14kn76wgn/T/tmp6QIoTv/pip.zip/pip/wheel.py",
>  line 205, in clobber
>os.makedirs(destdir)
>  File 
> "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py",
>  line 157, in makedirs
>mkdir(name, mode)
>OSError: [Errno 13] Permission denied: 
>'/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip'
>
>
>Storing debug log for failure in /Users/PaulSan/.pip/pip.log

You should run the command as root. Also, get-pip.py does not have to be in 
opt, it could be anywhere, eg.
sudo python ~/Downloads/get-pip.py

Another option is to download the .tar.gz pip from Pypi, untar it, cd to it, 
then 
sudo python setup.py install
 
If you don't have sufficient rights you might be able to do:
python setup.py --user

I believe 'sudo' is a Debian-specific thing.

regards,
Albert-Jan
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] multiprocessing question

2014-11-24 Thread Albert-Jan Roskam
 - Original Message -
 > From: Cameron Simpson 
 > To: Python Mailing List 
 > Cc: 
 > Sent: Monday, November 24, 2014 2:20 AM
 > Subject: Re: [Tutor] multiprocessing question
 > 
> On 23Nov2014 22:30, Albert-Jan Roskam  
> wrote:
>> I created some code to get records from a potentially giant .csv file. This 
> implements a __getitem__ method that gets records from a memory-mapped csv 
> file. 
> In order for this to work, I need to build a lookup table that maps line 
> numbers 
> to line starts/ends. This works, BUT building the lookup table could be 
> time-consuming (and it freezes up the app). The (somewhat pruned) code is 
> here: 
> http://pastebin.com/0x6JKbfh. Now I would like to build the lookup table in a 
> separate process. I used multiprocessing. In the crude example below, it 
> appears 
> to be doing what I have in mind. Is this the way to do it? I have never used 
> multiprocessing/threading before, apart from playing around. One specfic 
> question: __getitem__ is supposed to throw an IndexError when needed. But how 
> do 
> I know when I should do this if I don't yet know the total number of 
> records? If there an uever cheap way of doing getting this number?
> 
> First up, multiprocessing is not what you want. You want threading for this.
> 
> The reason is that your row index makes an in-memory index. If you do this in 
> a 
> subprocess (mp.Process) then the in-memory index is in a different process, 
> and 
> not accessable.
Hi Cameron,  Thanks for helping me. I read this page before I decided to go for 
multiprocessing: 
http://stackoverflow.com/questions/3044580/multiprocessing-vs-threading-python. 
I never *really* understood why cPython (with GIL) could have threading anyway. 
I am confused: I thought the idea of mutliprocessing.Manager was to share 
information.
>>> help(mp.Manager)
Help on function Manager in module multiprocessing:Manager()
    Returns a manager associated with a running server process
    
    The managers methods such as `Lock()`, `Condition()` and `Queue()`
    can be used to create shared objects.>>> help(mp.managers.SyncManager)
Help on class SyncManager in module multiprocessing.managers:class 
SyncManager(BaseManager)
 |  Subclass of `BaseManager` which supports a number of shared object types.
 |  
 |  The types registered are those intended for the synchronization
 |  of threads, plus `dict`, `list` and `Namespace`.
 |  
 |  The `multiprocessing.Manager()` function creates started instances of
 |  this class...>>> help(mp.Manager().dict)
Help on method dict in module multiprocessing.managers:dict(self, *args, 
**kwds) method of multiprocessing.managers.SyncManager instance  > Use a 
Thread. You code will be very similar.
Ok, I will try that.
> Next: your code is short enough to including inline instead of forcing people 
> to go to pastebin; in particular if I were reading your email offline (as I 
> might do on a train) then I could not consult your code. Including it in the 
> message is preferable, normally. Sorry about that. I did not want to burden 
> people with too many lines of code. The pastebin code was meant as the 
> problem context.
 
> Your approach of setting self.lookup_done to False and then later to True 
> answers your question about "__getitem__ is supposed to throw an IndexError  
> :-) Nice. I added those lines while editing the mail. 
 
> 
> when needed. But how do I know when I should do this if I don't yet know the 
> 
> total number of records?" Make __getitem__ _block_ until self.lookup_done 
> is 
> True. At that point you should know how many records there are.
> 
> Regarding blocking, you want a Condition object or a Lock (a Lock is simpler, 
> and Condition is more general). Using a Lock, you would create the Lock and 
> .acquire it. In create_lookup(), release() the Lock at the end. In 
> __getitem__ 
> (or any other function dependent on completion of create_lookup), .acquire() 
> and then .release() the Lock. That will cause it to block until the index 
> scan 
> is finished. So __getitem__ cannot be called while it is being created? But 
> wouldn't that defeat the purpose? My PyQt program around it initially shows 
> the first 25 records. On many occasions that's all what's needed.  
 
> A remark about the create_lookup() function on pastebin: you go:
> 
>   record_start += len(line)
THANKS!! How could I not think of this.. I initially started wth open(), which 
returns bytestrings.I could convert it to bytes and then take the len() 
> This presumes that a single text character on a line consumes a single byte 
> or 
> memory or file disc space. However, your data file is utf-8 encoded, and some 
> characters may be more than one byte or storage. This means that your 
> record_start values will not be useful because they are character counts, not 
> byte counts, and you need byte counts to offset into a file if you are doing 
> random access.
> 
> Instead, note the value of unicode_csv_data.tell() before

[Tutor] pexpect interactive password entry for luks device

2014-11-24 Thread Adam Gold
I'm trying to do something really simply (I think) with pexpect but must
be missing an obvious step.  I want to ssh from host to guest, establish
a CIFS connection on the guest to a share somewhere else on the local
network, open a luks loop device on the share by entering the password
(I don't want this to be non-interactive, either with a key file or by
including the password in the pexpect script) and then mounting the device.

I'm using the following code:

password = getpass.getpass('Enter passphrase for /opt/luks: ')
child = pexpect.spawn('ssh root@192.168.56.101')
child.interact()
child.sendline('mount.cifs -o credentials=/root/cred_f //192.168.56.1/f
/opt')
child.sendline('losetup /dev/loop0 /opt/luks')
child.sendline('cryptsetup luksOpen /dev/loop0 l')
child.expect('Enter passphrase for /opt/luks: ')
child.sendline(password)
child.sendline('mount /dev/mapper/l /opt')
child.sendline('exit')

The best that happens is the CIFS share gets mounted and the program
exits while leaving me in the child terminal.  I've tried varying the
placement of child.interact() but that makes no difference or replacing
the first line which uses getpass with a 'child.expect' line when the
password is required.

Could anyone help me?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] "Philosophical" question about string slicing from end of a string

2014-11-24 Thread boB Stepp
Python 2.7.8
Win7Pro

>>> str = "0123456789"
>>> str[-1]
'9'
>>> str[-3:-1]
'78'
>>> str[-3:]
'789'

I understand that the above is "the way it is" in Python, but I am
puzzled why the designers did not choose that str[-3:-1] returns
'789', especially since str[-1] returns '9'. What is the reason for
choosing Python's actual behavior?

-- 
boB
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "Philosophical" question about string slicing from end of a string

2014-11-24 Thread Zachary Ware
On Mon, Nov 24, 2014 at 12:32 PM, boB Stepp  wrote:
> Python 2.7.8
> Win7Pro
>
 str = "0123456789"
 str[-1]
> '9'
 str[-3:-1]
> '78'
 str[-3:]
> '789'
>
> I understand that the above is "the way it is" in Python, but I am
> puzzled why the designers did not choose that str[-3:-1] returns
> '789', especially since str[-1] returns '9'. What is the reason for
> choosing Python's actual behavior?

For the same reason as this behavior with positive indices:

>>> s = '0123456789'
>>> s[1]
'1'
>>> s[3]
'3'
>>> s[1:3]
'12'

Here's what you can do with it:

>>> s[-5:-3] + s[-3:-1] == s[-5:-1]
True
>>> len(s[-5:-3]) == -3 - -5
True

Think of slicing as "everything from this index (-3) up to but not
including (:) this index (-1)".

Have I clarified or muddied it for you? :)

Regards,
-- 
Zach
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "Philosophical" question about string slicing from end of a string

2014-11-24 Thread boB Stepp
On Mon, Nov 24, 2014 at 12:57 PM, Zachary Ware
 wrote:
[...]
>
> Have I clarified or muddied it for you? :)

Clarified, I believe, if my following statements are correct: I did
not consider that the behavior was symmetric with positive indices.
So, index 0 is the "center" relative to which positive and negative
indices create identical behaviors.

Thanks!

-- 
boB
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "Philosophical" question about string slicing from end of a string

2014-11-24 Thread boB Stepp
On Mon, Nov 24, 2014 at 1:06 PM, boB Stepp  wrote:
> On Mon, Nov 24, 2014 at 12:57 PM, Zachary Ware
>  wrote:
> [...]
>>
>> Have I clarified or muddied it for you? :)
>
> Clarified, I believe, if my following statements are correct: I did
> not consider that the behavior was symmetric with positive indices.
> So, index 0 is the "center" relative to which positive and negative
> indices create identical behaviors.
>
Hmm. There is a flaw in my observed "symmetry" in that str[0:3] and
str[-3:0] do not behave the same as the latter returns an empty
string.

-- 
boB
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "Philosophical" question about string slicing from end of a string

2014-11-24 Thread Zachary Ware
On Mon, Nov 24, 2014 at 1:06 PM, boB Stepp  wrote:
> On Mon, Nov 24, 2014 at 12:57 PM, Zachary Ware
>  wrote:
> [...]
>>
>> Have I clarified or muddied it for you? :)
>
> Clarified, I believe, if my following statements are correct: I did
> not consider that the behavior was symmetric with positive indices.
> So, index 0 is the "center" relative to which positive and negative
> indices create identical behaviors.

Hmm, either I'm not quite following you, or that's not quite right.
For the purposes of slicing, 0 is positive and slices that have either
all positive or all negative indices behave the same way.  Mixing
positive and negative indices is of course possible, but takes a
little bit more thought since you're counting from opposite ends.
Also note that there's no way to get the last member with a negative
second index.

[Received while writing the above]
On Mon, Nov 24, 2014 at 1:16 PM, boB Stepp  wrote:
> Hmm. There is a flaw in my observed "symmetry" in that str[0:3] and
> str[-3:0] do not behave the same as the latter returns an empty
> string.

Correct.  Here's another way to think about negative indices,
particularly for converting between positive and negative indices:

>>> s[-5:-3]
'56'
>>> len(s)-5
5
>>> len(s)-3
7
>>> s[len(s)-5:len(s)-3]
'56'
>>> s[5:7]
'56'

So, when you try to do s[-3:0], you're doing s[len(s)-3:0], which
equates to s[7:0].  Building from my example with the length of the
slice in my previous message, the length of that slice would be 0 - 7,
or -7, which obviously won't work very well!  Instead of bailing out
with an error there, Python just gives you the shortest substring it
can, ''.

[*] Btw, I've been using 's' instead of 'str' just because it's good
practice not to shadow builtin names like 'str'.
-- 
Zach
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "Philosophical" question about string slicing from end of a string

2014-11-24 Thread Steven D'Aprano
On Mon, Nov 24, 2014 at 12:32:27PM -0600, boB Stepp wrote:
> Python 2.7.8
> Win7Pro
> 
> >>> str = "0123456789"
> >>> str[-1]
> '9'
> >>> str[-3:-1]
> '78'
> >>> str[-3:]
> '789'
> 
> I understand that the above is "the way it is" in Python, but I am
> puzzled why the designers did not choose that str[-3:-1] returns
> '789', especially since str[-1] returns '9'. What is the reason for
> choosing Python's actual behavior?

The slice indexes fall *between* characters, not on them. So the string 
"abcdef" will have indexes:

|a|b|c|d|e|f|
0 1 2 3 4 5 6

(Things may not line up perfectly unless you read this will a monospaced 
font like Courier.)

Think of slicing as cutting on the lines, so the slice [1:4] cuts just 
before "b" and just after "d".

Negative indexes work the same way, just in the opposite direction:

 |a|b|c|d|e|f|
-6-5-4-3-2-1 ?

Note that the final line, marked with a question mark, would have been 0 
except that 0 is already used for positive slicing. 

So the slice [-3:-1] cuts before the "d" and just after "e".


-- 
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] multiprocessing question

2014-11-24 Thread Cameron Simpson

On 24Nov2014 12:56, Albert-Jan Roskam  wrote:

> From: Cameron Simpson 

On 23Nov2014 22:30, Albert-Jan Roskam 
wrote:

I created some code to get records from a potentially giant .csv file. This

implements a __getitem__ method that gets records from a memory-mapped csv file.
In order for this to work, I need to build a lookup table that maps line numbers
to line starts/ends. This works, BUT building the lookup table could be
time-consuming (and it freezes up the app). [...]

First up, multiprocessing is not what you want. You want threading for this.

The reason is that your row index makes an in-memory index. If you do this in a
subprocess (mp.Process) then the in-memory index is in a different process, and
not accessable.


Hi Cameron,  Thanks for helping me. I read this page before I decided to go for 
multiprocessing: 
http://stackoverflow.com/questions/3044580/multiprocessing-vs-threading-python. 
I never *really* understood why cPython (with GIL) could have threading anyway. 
I am confused: I thought the idea of mutliprocessing.Manager was to share 
information.


Regarding the GIL, it will prevent the raw python interpreter from using more 
than one CPU: no two python opcodes run concurrently. However, any calls to C 
libraries or the OS which may block release the GIL (broadly speaking). So 
while the OS is off reading data from a hard drive or opening a network 
connection or something, the Python interpreter is free to run opcodes for 
other python threads. It is timesharing at the python opcode level. And if the 
OS or a C library is off doing work with the GIL released then you get true 
multithreading.


Most real code is not compute bound at the Python level, most of the time.  
Whenever you block for I/O or delegate work to a library or another process, 
your current Python Thread is stalled, allowing other Threads to run.


For myself, I use threads when algorithms naturally fall into parallel 
expression or for situations like yours where some lengthy process must run but 
I want the main body of code to commence work before it finishes. As it 
happens, one of my common uses cases for  the latter is reading a CSV file:-)


Anywhere you want to do things in parallel, ideally I/O bound, a Thread is a 
reasonable thing to consider. It lets you write the separate task in a nice 
linear fashion.


With a Thread (coding errors aside) you know where you stand: the data 
structures it works on are the very same ones used by the main program. (Of 
course, therein lie the hazards as well.)


With multiprocessing the subprocess works on distinct data sets and (from my 
reading) any shared data is managed by proxy objects that communicate between 
the processes. That gets you data isolation for the subprocess, but also higher 
latency in data access between the processes and of course the task of 
arranging those proxy objects.


For your task I would go with a Thread.


when needed. But how do I know when I should do this if I don't yet know the

total number of records?" Make __getitem__ _block_ until self.lookup_done
is
True. At that point you should know how many records there are.

Regarding blocking, you want a Condition object or a Lock (a Lock is simpler,
and Condition is more general). Using a Lock, you would create the Lock and
.acquire it. In create_lookup(), release() the Lock at the end. In __getitem__
(or any other function dependent on completion of create_lookup), .acquire()
and then .release() the Lock. That will cause it to block until the index scan
is finished.


So __getitem__ cannot be called while it is being created? But wouldn't that 
defeat the purpose? My PyQt program around it initially shows the first 25 
records. On many occasions that's all what's needed.  


That depends on the CSV and how you're using it. If __getitem__ is just "give 
me row number N", then all it really needs to do is check against the current 
count of rows read.  Keep such a counter, updated by the scanning/indexing 
thread. If the requested row number is less than the counter, fetch it and 
return it.  Otherwise block/wait until the counter becomes big enough. (Or 
throw some exception if the calling code can cope with the notion of "data not 
ready yet".)


If you want __getitem__ to block, you will need to arrange a way to do that.  
Stupid programs busy wait:


 while counter < index_value:
   pass

Horrendous; it causes the CPU to max out _and_ gets in the way of other work, 
slowing everything down. The simple approach is a poll:


 while counter < index_value:
   sleep(0.1)

This polls 10 times a second. Tuning the sleep time is a subjective call: too 
frequent will consume resources, to infrequent will make __getitem__ too slow 
to respond when the counter finally catches up.


A more elaborate but truly blocking scheme is to have some kind of request 
queue, where __getitem__ makes (for example) a Condition variable and queues a 
request for "when the counter reaches this number". When t

Re: [Tutor] attempting to install PIP

2014-11-24 Thread Paul LaBerge
Thanks for all your suggestions. I took the option of downloading .tar.gz pip 
from PyPI; untar; cd to it; then;

sudo python setup.py install


This installed successfully finishing with:

Processing dependencies for pip==6.0.dev1
Finished processing dependencies for pip==6.0.dev1


Depending on where I read it seemed to require setuptools. I installed it with 
a similar method. 

~/Desktop/setuptools-7.0$ sudo python setup.py install


I thought that might fix trying to install virtualenv. 

$ pip install virtualenv
-bash: pip: command not found


This looks like a PATH omission. I found a file pip in the directory below and 
tried to install virtualenv again but again received the command not found 
error. 

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin$


I also looked in /usr and /opt and beneath to try to find the pip application 
but without success. 

Can you tell me where to find the pip application so I can use it and add it to 
my Path ?

Overall: based on my reading; if I have Python, Pip, Install Tools, and Virtual 
Environment I’ll be able to install and use a PyPI package. 

I had also installed MacPorts to be able to install the SciPy stack from 
scipy.org . It contains several scientific packages needed 
for the PyPI package. 

thanks,

Paul

___
> On Nov 24, 2014, at 4:10 AM, Albert-Jan Roskam  wrote:
> 
> 
>> From: Paul LaBerge 
>> To: tutor@python.org 
>> Sent: Monday, November 24, 2014 6:05 AM
>> Subject: [Tutor] attempting to install PIP
>> 
>> 
>> 
>> Hello,
>> I’m trying to install PIP on a Mac running Yosemite. I downloaded get-pip.py 
>> from https://pip.pypa.io/en/latest/installing.html. I copied it to 
>> /usr/local/bin/ then  ran python get-pip.py. It repeatedly downloaded 
>> something up to a count of 100. From looking at the debug log it seems it 
>> was checking every version of PIP back to 0.2 before selecting version 
>> 1.5.6. 
>> Using version 1.5.6 (newest of versions: 1.5.6, 1.5.6, 0.2)
>> 
>> 
>> The result was:
>> snip
>> 99  Downloading pip-1.5.6-py2.py3-none-any.whl (1.0MB): 100  Downloading 
>> pip-1.5.6-py2.py3-none-any.whl (1.0MB):  Downloading 
>> pip-1.5.6-py2.py3-none-any.whl (1.0MB): 1.0MB downloaded
>> Installing collected packages: pip
>> Cleaning up...
>> Exception:
>> Traceback (most recent call last):
>> File 
>> "/var/folders/ft/pthcg_6j06zfdp0sl14kn76wgn/T/tmp6QIoTv/pip.zip/pip/basecommand.py",
>>  line 122, in main
>>   status = self.run(options, args)
>> File 
>> "/var/folders/ft/pthcg_6j06zfdp0sl14kn76wgn/T/tmp6QIoTv/pip.zip/pip/commands/install.py",
>>  line 283, in run
>>   requirement_set.install(install_options, global_options, 
>> root=options.root_path)
>> File 
>> "/var/folders/ft/pthcg_6j06zfdp0sl14kn76wgn/T/tmp6QIoTv/pip.zip/pip/req.py",
>>  line 1435, in install
>>   requirement.install(install_options, global_options, *args, **kwargs)
>> File 
>> "/var/folders/ft/pthcg_6j06zfdp0sl14kn76wgn/T/tmp6QIoTv/pip.zip/pip/req.py",
>>  line 671, in install
>>   self.move_wheel_files(self.source_dir, root=root)
>> File 
>> "/var/folders/ft/pthcg_6j06zfdp0sl14kn76wgn/T/tmp6QIoTv/pip.zip/pip/req.py",
>>  line 901, in move_wheel_files
>>   pycompile=self.pycompile,
>> File 
>> "/var/folders/ft/pthcg_6j06zfdp0sl14kn76wgn/T/tmp6QIoTv/pip.zip/pip/wheel.py",
>>  line 215, in move_wheel_files
>>   clobber(source, lib_dir, True)
>> File 
>> "/var/folders/ft/pthcg_6j06zfdp0sl14kn76wgn/T/tmp6QIoTv/pip.zip/pip/wheel.py",
>>  line 205, in clobber
>>   os.makedirs(destdir)
>> File 
>> "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py",
>>  line 157, in makedirs
>>   mkdir(name, mode)
>> OSError: [Errno 13] Permission denied: 
>> '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip'
>> 
>> 
>> Storing debug log for failure in /Users/PaulSan/.pip/pip.log
> 
> You should run the command as root. Also, get-pip.py does not have to be in 
> opt, it could be anywhere, eg.
> sudo python ~/Downloads/get-pip.py
> 
> Another option is to download the .tar.gz pip from Pypi, untar it, cd to it, 
> then 
> sudo python setup.py install
> 
> If you don't have sufficient rights you might be able to do:
> python setup.py --user
> 
> I believe 'sudo' is a Debian-specific thing.
> 
> regards,
> Albert-Jan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] ran into a problem with pip install

2014-11-24 Thread Clayton Kirkwood
I was trying to pip install beautifulsoup and ran into the following error.
It appears to be 2.x because of the print. I am installing to a python
3.4.2. What do I need to do? I tried to log a bug report to PyPI Bug Reports
but that apparently isn't the cool thing to do. I can't perceive why the
test failed.

 

 

TIA,

 

Clayton

 

 

 

Microsoft Windows [Version 6.0.6002]

Copyright (c) 2006 Microsoft Corporation.  All rights reserved.

 

C:\Users\Dad>pip requests

ERROR: unknown command "requests"

 

C:\Users\Dad>pip requests install

ERROR: unknown command "requests"

 

C:\Users\Dad>pip install requests

Downloading/unpacking requests

Installing collected packages: requests

Successfully installed requests

Cleaning up...

 

C:\Users\Dad>pip install beautiful

Downloading/unpacking beautiful

  Could not find any downloads that satisfy the requirement beautiful

Cleaning up...

No distributions at all found for beautiful

Storing debug log for failure in
C:\Windows\system32\config\systemprofile\pip\pi

p.log

 

C:\Users\Dad>pip install beautifulsoup

Downloading/unpacking beautifulsoup

  Downloading BeautifulSoup-3.2.1.tar.gz

  Running setup.py
(path:C:\Windows\system32\config\SYSTEM~1\AppData\Local\Temp\

pip_build_SYSTEM\beautifulsoup\setup.py) egg_info for package beautifulsoup

Traceback (most recent call last):

  File "", line 17, in 

  File
"C:\Windows\system32\config\SYSTEM~1\AppData\Local\Temp\pip_build_SYS

TEM\beautifulsoup\setup.py", line 22

print "Unit tests have failed!"

  ^

SyntaxError: Missing parentheses in call to 'print'

Complete output from command python setup.py egg_info:

Traceback (most recent call last):

 

  File "", line 17, in 

 

  File
"C:\Windows\system32\config\SYSTEM~1\AppData\Local\Temp\pip_build_SYSTEM\

beautifulsoup\setup.py", line 22

 

print "Unit tests have failed!"

 

  ^

 

SyntaxError: Missing parentheses in call to 'print'

 



Cleaning up...

Command python setup.py egg_info failed with error code 1 in
C:\Windows\system32

\config\SYSTEM~1\AppData\Local\Temp\pip_build_SYSTEM\beautifulsoup

Storing debug log for failure in
C:\Windows\system32\config\systemprofile\pip\pi

p.log

 

C:\Users\Dad>

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] ran into a problem with pip install

2014-11-24 Thread Zachary Ware
On Mon, Nov 24, 2014 at 10:28 PM, Clayton Kirkwood  wrote:
> I was trying to pip install beautifulsoup and ran into the following error.
> It appears to be 2.x because of the print.

Your diagnosis is correct, beautifulsoup 3.2.1 is written for Python 2.

> I am installing to a python 3.4.2. What do I need to do?

Install beautifulsoup4.

Just to note, I know nothing about beautifulsoup, having never used
it.  I determined the proper solution by doing a Google search for
"beautifulsoup", which turned up two different PyPI links as the 4th
and 5th results.  Opening both of them, the one for 'BeautifulSoup
3.2.1' says "This package is OBSOLETE. It has been replaced by the
beautifulsoup4 package. You should use Beautiful Soup 4 for all new
projects."

> I tried to log a bug report to PyPI Bug Reports
> but that apparently isn’t the cool thing to do.

What do you mean by that?  However, note that this was not a PyPI bug;
if anything, it's a bug in beautifulsoup's setup.py not specifying
that it is a Python2-only package, which is not likely to change since
the package is marked as obsolete.  By the way, it is good to confirm
that there is actually a reproducible bug before opening a bug report
anywhere; frivolous reports of non-bugs are mildly annoying at best
and rage-inducing at worst (depending on how your day has been :).

> I can’t perceive why the test failed.

You already diagnosed it: it was trying to run Python2-only code on Python3.

Also, please try to avoid sending mail to this (or any) list in HTML
or "rich text" format.  Plain text is far easier for everyone else to
deal with, from being able to actually read your message to being able
to reply without having to reformat your entire message.  Your client
(which appears to be Outlook?) does at least include a plain text
version with the HTML, but here's how it looks:
https://mail.python.org/pipermail/tutor/2014-November/103477.html

Hope this helps,
-- 
Zach
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] multiprocessing question

2014-11-24 Thread eryksun
On Sun, Nov 23, 2014 at 7:20 PM, Cameron Simpson  wrote:
>
> A remark about the create_lookup() function on pastebin: you go:
>
>  record_start += len(line)
>
> This presumes that a single text character on a line consumes a single byte
> or memory or file disc space. However, your data file is utf-8 encoded, and
> some characters may be more than one byte or storage. This means that your
> record_start values will not be useful because they are character counts,
> not byte counts, and you need byte counts to offset into a file if you are
> doing random access.

mmap.readline returns a byte string, so len(line) is a byte count.
That said, CsvIter._get_row_lookup shouldn't use the mmap
object. Limit its use to __getitem__.

In CsvIter.__getitem__, I don't see the need to wrap the line in a
filelike object. It's clearly documented that csv.reader takes an
iterable object, such as a list. For example:

# 2.x csv lacks unicode support
line = self.data[start:end].strip()
row = next(csv.reader([line]))
return [cell.decode('utf-8') for cell in row]

# 3.x csv requires unicode
line = self.data[start:end].strip()
row = next(csv.reader([line.decode('utf-8')]))
return row

CsvIter._get_row_lookup should work on a regular file from built-in
open (not codecs.open), opened in binary mode. I/O on a regular file
will release the GIL back to the main thread. mmap objects don't do
this.

Binary mode ensures the offsets are valid for use with
the mmap object in __getitem__. This requires an ASCII compatible
encoding such as UTF-8.

Also, iterate in a for loop instead of calling readline in a while loop.
2.x file.__next__ uses a read-ahead buffer to improve performance.
To see this, check tell() in a for loop.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "Philosophical" question about string slicing from end of a string

2014-11-24 Thread eryksun
On Mon, Nov 24, 2014 at 1:33 PM, Zachary Ware
 wrote:
> Also note that there's no way to get the last member with a negative
> second index.

Also note that, given a -1 step, there's no way to get the first
member with a non-negative second index.

>>> s[-1:0:-1]
'987654321'

It requires a negative index that's at least one less than the
negative index of the first member:

>>> s[-1:-len(s)-1:-1]
'9876543210'

If possible, leave this implicit in the slice:

>>> s[::-1]
'9876543210'
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor