2

I'm trying to install pyobfuscate found here: https://github.com/astrand/pyobfuscate on my macOS Sierra using the following command python setup.py installbut I get the following error:

running install
running build
running install_data
copying pyobfuscate -> /usr/bin
error: [Errno 1] Operation not permitted: '/usr/bin/pyobfuscate'

I've tried using sudo as well but I get the exact same error.

Tak
  • 3,536
  • 11
  • 51
  • 93
  • you probably don't have write permission to that directory. You could use `sudo` to elevate your privilege. – AChampion Apr 25 '17 at 02:08
  • @AChampion I've tried using `sudo` as well but same error – Tak Apr 25 '17 at 02:09
  • The easy answer is to set up a virtualenv in your home directory so `/usr/bin` isn't being modified. – Charles Duffy Apr 25 '17 at 02:13
  • See [Mac OS don't have permission to usr/bin folder at all](http://stackoverflow.com/questions/32901372/mac-os-dont-have-permission-to-usr-bin-folder-at-all) -- since El Capitan, `/usr/bin` is entirely read-only unless System Integrity Protection is disabled. – Charles Duffy Apr 25 '17 at 02:13
  • That said, if all `setup.py install` is doing is copying this binary, have you considered copying it somewhere else -- like `/usr/local/bin`? – Charles Duffy Apr 25 '17 at 02:16
  • You could also use `python setup.py install --prefix=/usr/local`. – Charles Duffy Apr 25 '17 at 02:18
  • @CharlesDuffy just tried this `python setup.py install --prefix=/usr/local` and gave the same result – Tak Apr 25 '17 at 02:18
  • You still need `sudo` to write to `/usr/local/bin`. Unless by "the same result" you mean it said it was trying to write to `/usr/bin/pyobfuscate` instead of `/usr/local/bin/pyobfuscate`. – Charles Duffy Apr 25 '17 at 02:19
  • (That kind of ambiguity is why saying "the same result" is much less useful than a log of the *exact* output). – Charles Duffy Apr 25 '17 at 02:20
  • @CharlesDuffy sorry. Yes, I tried with `sudo` but it tries to write in `/usr/bin/pyobfuscate` instead of `/usr/local/bin/pyobfuscate` – Tak Apr 25 '17 at 02:21
  • Okay, *that's* helpful. I'll want to look at the `setup.py` for that specific program. Unfortunately, I'm being called to dinner right now. – Charles Duffy Apr 25 '17 at 02:21
  • (You might try the virtualenv route while I'm away). – Charles Duffy Apr 25 '17 at 02:22
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/142556/discussion-between-tak-and-charles-duffy). – Tak Apr 25 '17 at 02:22
  • @CharlesDuffy no worries, enjoy your dinner. I've tried using virtualenv as shown here http://python-guide-pt-br.readthedocs.io/en/latest/dev/virtualenvs/ and then I have this in my terminal `(pyobfuscateVirtual) UserA-MBP:pyobfuscate usera` and once I run this `$ sudo python setup.py install` I get the same error. – Tak Apr 25 '17 at 02:34
  • Back from dinner, joining the chat. :) – Charles Duffy Apr 25 '17 at 02:42
  • Filed this as https://github.com/astrand/pyobfuscate/issues/19, btw. – Charles Duffy Apr 25 '17 at 03:11

2 Answers2

1

In general: Avoid /usr/bin on current MacOS (where it's read-only)

/usr/bin isn't writable on new versions of MacOS, even as root, unless System Integrity Protection has been disabled. Consider:

sudo python setup.py install --prefix=/usr/local

Another option, which doesn't require sudo at all, is to use a virtualenv:

virtualenv ~/pyobfuscate.venv     ## create a virtualenv
. ~/pyobfuscate.venv/bin/activate ## activate that virtualenv
python setup.py install           ## install pyobfuscate in that virtualenv

...and thereafter, . ~/pyobfuscate.venv/bin/activate in a given shell before running pyobfuscate in that shell.


But pyobfuscate's setup.py needs to be fixed before you can do that:

That said, current versions of pyobfuscate have their setup.py written as follows:

data_files=[('/usr/bin', ['pyobfuscate'])]

That's inappropriate, and instead, should be:

scripts=['pyobfuscate']

...which will follow the prefix given, whether via a virtualenv or a --prefix= argument.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
  • I tried with `sudo` but didn't work as it tries to write in `/usr/bin/pyobfuscate` instead of `/usr/local/bin/pyobfuscate` – Tak Apr 25 '17 at 02:19
  • Ahh. Reading the `setup.py`, I see why it wasn't working -- answer edited appropriately. – Charles Duffy Apr 25 '17 at 02:52
0

Inside setup.py replace

data_files=[('/usr/bin', ['pyobfuscate'])]

with

scripts=['pyobfuscate']
Abhishek Pansotra
  • 947
  • 2
  • 13
  • 17