pip install optional dependencies with zsh [duplicate] - pip

I am trying to run a python urllib2 script and getting this error:
InsecurePlatformWarning: A true SSLContext object is not available.
This prevents urllib3 from configuring SSL appropriately and may cause
certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
After googling the error the solution, on stack overflow is to download requests' security package:
pip install requests[security]
But when I run that I get the error...
zsh: no matches found: requests[security]
Anyone know why zsh isn't picking up this library, it installs/upgrades requests just fine, I don't know why this isn't working
I am running this on a Debian Server...

zsh uses square brackets for globbing / pattern matching.
That means that if you need to pass literal square brackets as an argument to a command, you either need to escape them or quote the argument like this:
pip install 'requests[security]'
If you want to disable globbing for the pip command permanently, you can do so by adding this to your ~/.zshrc:
alias pip='noglob pip'

Related

If a project's Ruby version is explicitly specified, could changing from RVM to rbenv introduce bugs?

I'm trying to figure out if it's possible that a bug I'm experiencing could be related to the fact that I use rbenv but the rest of my team uses RVM.
What I've been trying to figure out is whether the executables created by rbenv/RVM for a specific Ruby are the same. If the Ruby version and gem versions are explicitly specified in the .ruby_version and Gemfile respectively, is it possible that rbenv and RVM interpret code differently or should I expect identical outcomes?
UPDATE. A description of the actual bug I'm experiencing was requested, so here it is.
Essentially, the project is using the dotenv gem (and dotenv-rails) to read a .env file in the root directory. Two of the values (a salt and an IV) are Base64 encoded strings that contain newline characters. At some point in the decoding process, an extra backslash is being added before each newline character, causing the decryption to fail. The problem is, the dotenv gem appears to be reading the file correctly (i.e. running Dotenv.load in Rails console shows the strings parsed correctly), so it's some other gem or extension deeper in the stack causing the problem. And we have yet to identify it.
Our quick fix was to gsub the doubly escaped newlines (similar to this foreman bug fix, but some members of the team don't want to merge it because they're convinced it's an environment problem caused by rbenv. I don't think this is the case, but am wondering if it's a possibility before I try uninstalling rbenv and switching to RVM, which I really don't want to do.
UPDATE #2. Problem solved!
I did end up switching to RVM, but to no avail. However it did end up being an environment issue.
It was because my default shell is zsh but most of my team uses bash, and we were using heroku local:run to spin up the local dev environment. heroku local:run, it turns out, uses your default shell environment. Even if you make the call from a different shell (such as bash). However both rails console and heroku local:run rails console use sh by default. And zsh was handling the import of the env vars differently than bash and sh.
No, the binaries compiled by rvm and rbenv are not the same, and they are not drop-in compatible. (e.g., you cannot compile ruby with rvm and then drop it into an existing rbenv setup) The compilation options provided to each are different, and the resulting files are handled differently.
That said, you should consider two ruby binaries of the same version that were compiled with the same options to be binary-compatible; that is, any Ruby code that runs through one binary should run the same way through the other binary, regardless of what platform they were compiled on, provided they were compiled with the same options and libraries.
For example, if rvm is compiled without OpenSSL support you will have no end of trouble when trying to use libraries that rely on cryptographic functions. Likewise with bad versions of readline.
You can conduct a very simple experiment to determine the problem: compile ruby with both on the same computer and run your experiment through both versions.
For the specific problem you have outlined (dotenv and extra linebreaks), pay attention to the difference between single quoted and double quoted strings, and how Ruby handles control characters in them. Ruby interprets escape sequences in double quoted strings only, so you can likely resolve your issue by ensuring your value is always single quoted.

where do I install custom completions for a python command line script on OSX

In the bash-completions read me it states:
Q. I author/maintain package X and would like to maintain my own
completion code for this package. Where should I put it to be sure
that interactive bash shells will find it and source it?
Install it in one of the directories pointed to by
bash-completion's pkgconfig file variables. There are two
alternatives: the recommended one is 'completionsdir' (get it with
"pkg-config --variable=completionsdir bash-completion") from which
completions are loaded on demand based on invoked commands' names,
so be sure to name your completion file accordingly, and to include
for example symbolic links in case the file provides completions
for more than one command. The other one which is present for
backwards compatibility reasons is 'compatdir' (get it with
"pkg-config --variable=compatdir bash-completion") from which files
are loaded when bash_completion is loaded.
However, on OS X after installing bash-comletion via homebrew this doesn't work:
pkg-config --variable=completionsdir bash-completion
Package bash-completion was not found in the pkg-config search path.
Perhaps you should add the directory containing `bash-completion.pc'
to the PKG_CONFIG_PATH environment variable
No package 'bash-completion' found
How/where would I install custom completions for a command line script I've written and will install via pip?
use echo $BASH_COMPLETION in the terminal to get where the bash completion are installed
if you used homebrew it's most likely in /usr/local/etc/bash_completion.d/

pythonbrew does not install python with no output on command line

I'm new to both python, pythonbrew and ubuntu. I need python 2.6 and currently have 2.7 on my ubuntu precise system. Searching online revealed that I should not try to uninstall 2.7 as that would pretty much destroy the OS, but get pythonbrew instead, that manages multiple python installations.
I tried installing pythonbrew, but the curl install (curl -kL https://raw.githubusercontent.com/utahta/pythonbrew/master/pythonbrew-install | bash) did not work for me: it was not picking up my http proxy from env, and then not passing it to the install script, once I provided it on the command line. I downloaded the pythonbrew bits manually and then used python setup.py install to install it. I did it as root and it seemed to work (installing under /root/.pythonbrew, which was not the best), however I could not use it as a different user on the system (permission problems). After some more reading I executed the script correctly as root user and it installed pythonbrew to /usr/local/pythonbrew (yay).
Now, when I execute the following as root or non root user, it waits for a while and then the prompt comes back with no error or any other information (--verbose makes no difference):
root#xxx:~/.pythonbrew/scripts/pythonbrew# pythonbrew install 2.6
root#xxx:~/.pythonbrew/scripts/pythonbrew#
Any ideas? I'm guessing this has something to do with the proxy again, but I'm completely new to python so any pointers are welcome.
Following the "which pythonbrew" and doing some guessing the following solved my problem: I changed the curl.py file under /usr/local/pythonbrew/scripts/pythonbrew adding proxy setting to read, readheader and fetch functions as follows:
before modification:
p = Popen('curl -skL "%s"' % url, stdout=PIPE, shell=True)
after modification:
p = Popen('curl -x http://<proxy host>:<proxy port> -skL "%s"' % url, stdout=PIPE, shell=True)
I am not sure why there was no output without the proxy setting, but now the install works!
I also faced this issue today, while installing py2.7.14 with pythonbrew.
The reason it silently fails to install is when it gets the header from the python server (src of py2.7.14), it checks for a return status of success. It implements HTTP/1.1 method check (only) where successful return status is 200 OK.
However, python server uses HTTP/2 and the success return code is in the form 200, there's no trailing OK.
So, to fix it, I added 2 lines of code below following 2 lines in /opt/.pythonbrew/scripts/pythonbrew/curl.py, routine readheader().
if re.match('^HTTP.*? 200 OK$', line):
break
Added this code below above code:
elif re.match('^HTTP.*? 200$', line):
break
I did't want to change pythonbrew's code, hence added it with an elif.
This works.
I note that several other people using pyenv also mentions of similar issue, I am presuming similar issue may exist there.

Problems installing Python Protocol Buffers

I am a beginning programmer trying to install the Python Protocol Buffers from this package: http://code.google.com/p/protobuf/downloads/detail?name=protobuf-2.4.1.zip
The readme states:
1) Make sure you have Python 2.4 or newer. If in doubt, run:
$ python -V
2) If you do not have setuptools installed, note that it will be
downloaded and installed automatically as soon as you run setup.py.
If you would rather install it manually, you may do so by following
the instructions on this page:
http://peak.telecommunity.com/DevCenter/EasyInstall#installation-instructions
3) Build the C++ code, or install a binary distribution of protoc. If
you install a binary distribution, make sure that it is the same
version as this package. If in doubt, run:
$ protoc --version
4) Run the tests:
$ python setup.py test
If some tests fail, this library may not work correctly on your
system. Continue at your own risk.
Please note that there is a known problem with some versions of
Python on Cygwin which causes the tests to fail after printing the
error: "sem_init: Resource temporarily unavailable". This appears
to be a bug either in Cygwin or in Python:
http://www.cygwin.com/ml/cygwin/2005-07/msg01378.html
We do not know if or when it might me fixed. We also do not know
how likely it is that this bug will affect users in practice.
5) Install:
$ python setup.py install
This step may require superuser privileges.
NOTE: To use C++ implementation, you need to install C++ protobuf runtime
library of the same version and export the environment variable before this
step. See the "C++ Implementation" section below for more details.
I have added both python and version 2.4.1 of protoc.exe into my PATH. However, when I try to run the test, I get an error message that says there's invalid syntax on line 38:
print "Can't find required file " + source
Okay, so it's missing parenthesis. I add them, and it encounters two more print statement syntax error messages. I fix those, and it encounters a syntax error message on an 'except' statement. What am I doing wrong?
Thanks.
Perhaps you are using Python 3?
The code you refer to will only work in Python 2.X
I have followed same steps , but I didn't get any errors.
Please make sure that you are getting correct Python and protoc version.
Export the environment LD_LIBRARY_PATH variable.

Unable to find a tab completion for Rubygem in Bash/Zsh

I have not found a tab-completion script for RubyGem in Bash/Zsh.
Where can you get the tab-completion script for RubyGem in Bahs/Zsh?
Executable RubyGem commands are installed into /usr/bin or /usr/local/bin or whatever prefix Ruby is found under. Tab completion for commands should just work just like any other executable file in your PATH. If it's not working, verify that the directory RubyGems installs commands into is in your PATH.
There is currently no official method of doing tab completion for the parameters to any of these commands. If you need tab completion for a command installed via RubyGems, you'll need to write and/or install it yourself. See the Bash reference manual for details. There may already be a completion system for the specific command you're interested in, so be sure to google for it, but most commands installed via RubyGems do not have any auto-complete written for them.
Try:
http://github.com/oggy/ruby-bash-completion
To install it just copy gem file to /etc/bash_completion.d/
I had errors when trying to tab:
gem install
Because I didn't have some cache files in .gem directory. So I simply disabled it by editing gem file. I changed _gem_all_names function:
function _gem_all_names {
echo ""
}
That github-hosted bash completion is now part of Ubuntu Lucid Lynx. Sweet! If you apt-get install rubygems1.8 then the completion (commands and options!) should just work.
Unfortunately, as installed, it will only complete if it sees invocation of gem1.8, and not the more conventient gem. You can fix that manually if so inclined by extending the last line of /etc/bash_completion.d/gem1.8 to include gem as part of the complete name list. I'm sure there's a cleaner way, but that works.
This is (years) late, but as I was highly unsatisfied with the various completion scripts for gem that seem to be floating around the net, I decided to write my own based (somewhat) on the rather nice git completion script available in git-sh.
https://github.com/pdkl95/rubygems-completion

Resources