How can I run runsnakerun on Mac OS X inside a conda environment? - macos

I've created a conda environment so I can use runsnakerun on my Mac as follows:
conda create -n runsnake wxPython
source activate runsnake
pip install runsnakerun
However, when I now attempt to use runsnake I get:
$ runsnake
This program needs access to the screen.
Please run with a Framework build of python, and only when you are
logged in on the main display of your Mac.
How can I get runsnake to work?

The problem is that conda's python is not a "framework python" on Mac, their decision is that you have to use pythonw instead. Unfortunately, pip builds entry point scripts using python not pythonw and, to make matters worse, RunSnakeRun does a horrible subprocess dance to launch itself in 32-bit mode on 64-bit macs.
The upshot is that the only hacky workaround I can think of to launch runsnake is as follows:
VERSIONER_PYTHON_PREFER_32_BIT=yes pythonw `which runsnake32`
I'm not actually sure that environment variable is even needed anymore, but the above does what the entry point appears to be trying to do and does at least start the RunSnakeRun gui.

Related

Downgrade Python without change behavior of base environment

I'm trying to switch over to using Mamba for my Python installation (Windows 10). Previously, I've just been installing Python using the installer from python.org and pip.
However, I have some one-off scripts I'd like to be able to run in a default environment without having to use source activate $env every time. The newest version of Mamba uses Python 3.10, but most of these scripts were written for Python 3.9.7. I'd like to downgrade the Python installation in the default environment to 3.9.7. I've tried doing this using mamba install python=3.9.7, which initially seems to work.
However, I get the following problem. When I run Python 3.10 using python in a command prompt after installing Mamba (i.e., before running the previous command to downgrade to 3.9.7), the interpreter launches and works correctly. Any packages I add to the base environment become available.
But after I downgrade the base environment to Python 3.9.7, I get the following warning when running python:
Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated. Libraries may fail to load. To activate this environment
please see https://conda.io/activation
The interpreter does launch, but packages added to the base environment indeed fail to load when I attempt to import them.
I can get around this by running mamba activate base (though for some reason I don't understand, this is only successful from cmd and not PowerShell, which is annoying, since that's the shell I use by default). After this, python launches the interpreter without any warnings, and packages added to the base environment load as expected.
But what I'd like to do is downgrade Python to 3.9.7 and make it work like the default 3.10 environment, where the base environment is available without needing to manually activate it every time, since this is what I want for my one-off scripts that I want to be able to just run by clicking on them.
Is there a way I can downgrade the version of Python in Mamba's base environment, but make it work like the prepackaged version (i.e., without needing to issue mamba activate base every time)? Is the way to do this just to use an older version of Mamba that comes with Python 3.9.7?
"Is there a way I can downgrade the version of Python in Mamba's base environment...?"
Yes, but you shouldn't. It's best to leave base alone - it should strictly be used for Conda/Mamba infrastructure, not for running user scripts. If you want a default Python 3.9.7 environment, then create one, disable auto_activate_base, and have that new environment activate when your shell starts up.

ModuleNotFoundError: No Module Named 'requests' VSCODE Mac OS

I am having a problem running my script in VSCode.
I have tried the following:
Reinstalling requests through pip, easy_install, and sudo pip
Importing requests directly in the Python interpreter (which worked)
This leads me to believe that VSCode isn't using the correct interpreter that actually has the package installed.
You can choose your interpreter in VS Code in several ways. One of them is by clicking the tab in the bottom toolbar (lower-left) which might say "Python 3.9.4 (64-bit)", upon which you will be able to select from a menu of choices, e.g. /usr/bin/python3 or a conda or brew installation, etc.
I think yours is python environment problem. To check whether it's python environment or not, you can use which python (or which python3 if you use python3) command in your both vscode terminal and mac terminal. If you see different python path, then your vscode is using different python environment. You can change the python interpreter in vscode to have same environment as your mac terminal.
Open Command Palette in vscode with ⇧⌘P
Type "Python: Select Interpreter"
Then, choose the same environment as your mac terminal (If you want the same one, you can choose the same python environment path as mac terminal that you get with "which python" or "which python3").
You may be able to find a solution here: ImportError: No module named requests
You haven't mentioned using different versions in your commands. It's possible you need to use pip3 instead of pip, or python3 instead of python.

Can't run utop in the terminal

I have to start learning OCaml language.
In order to practice it at home we have to install some devices following the tutorial made by our University. Since we use Debian at school, it's a bit different when I have to use windows at home and here I come: I don't manage to run the tools properly.
We have to install OCaml via the official site. After doing it, I run "Cygwin64 Terminal" and had to type these commands:
$ opam update
$ opam install utop merlin ocp-indent
It has been done successfully. However when I try to run utop by its command I get this message:
"utop.exe: GetConsoleScreenBufferInfo: Bad file descriptor"
Where did I fail? What do I have to do?
I have the same error after installing ocaml for windows from http://fdopen.github.io/opam-repository-mingw/installation/ (graphic installer, 64 bits)
BUT the error happened ONLY after running opam install utop
Precisely, after running the graphic installer alone, I can launch ocaml (not utop) without error, either from a cygwin terminal or a windows shell (cmd.exe).
If I run opam install utop, I can no longer launch ocaml (cannot exec, segmentation fault) nor utop (GetConsoleScreenBufferInfo: Bad file descriptor)
If I uninstall utop and its dependencies, keeping only the base modules installed by the graphic installer, it is still impossible to launch ocaml.
Only solution found till now : completely remove ocaml and reinstall it ... but there's certainly a better way !

Python 3.6 Mac OS X - How do you get PIP install?

In various educational guides, I have been guided to install Python modules with an easy one-line command entered in the terminal: pip install whatever
Well, when I type "pip install" it is not found.
Elsewhere in Stack Overflow the following instructions have been given:
Use apt-get -- but I am not using linux
Use easy-install pip -- but
it also produces command not found.
Use easy-install3 pip -- same problem: command not found.
Does PIP not install when you install Python 3.6?
Do I really have to edit the path myself - it seems to me, if necessary, the developers who created the installer would have done this and the path would have been updated when Python was installed.
Poking around the hidden system folders in OS X, I see that there is an alias called pip3.6 in usr/local/bin that was created a week ago when I installed Python 3.6.
I would try:
pip3.6 install whatever
Right, worked it out now.
Pip is installed when Python 3.6 is installed - but instead of typing "pip install", you type:
pip3.6 install <ModuleYouWant>
I guess this is so people can run Python 2.7 and 3.6 simultaneously.. it'd be nice if it were a little more intuitive though, or there were some instructions, or it just worked as pip gave you the option "2.7 or 3.6?"
For those OS X users in the dark like I was, please note that system files like the usr folder can be seen in Finder if you press Command+Shift+G then in the dialog box that pops up type /usr (There are other ways to see hidden folders too).

Using Google App Engine SDK with Python 2.7 on Mac OS X 10.6

I need to run Python 2.7 on my Mac Snow Leopard, which has Python 2.6 installed. According to this answer, running the Python 2.7 mpkg installer from Python.org should get me there.
The reason I need to do this is that I'm trying to run the Google App Engine SDK for the Python 2.7 runtime.
After installing Python 2.7, I'm still getting the following warning in my GAE server log:
Warning: You are using a Python runtime (2.6) that is older than the
production runtime environment (2.7).
What else must I do to get the GAE SDK to recognize the new Python version?
EDIT 2:
Running:
$ sudo find / -name python2.7
I get:
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/usr/local/bin/python2.7
According to the answers I went into GoogleAppLauncher -> Preferences and set the Python path to each of these, and each time I get the exact same error.
Running dev_appserver with the following flags:
--admin_console_server= --port=8081 Python command: /Library/Frameworks/Python.framework/Versions/2.7 2011-11-14
16:12:24.726 GoogleAppEngineLauncher[57590:203] *** NSTask: Task
create for path '/Library/Frameworks/Python.framework/Versions/2.7'
failed: 22, "Invalid argument". Terminating temporary process.
Another Wierd thing is, it always tries to resolve to the same path, no matter which of those I plug in; It always reverts to /Library/Frameworks/Python.framework/Versions/2.7
EDIT 3:
OK, after entering the paths into the prefs field repeatedly, I finally just cleared it out, and somehow it's now pointing to the right place:
Running dev_appserver with the following flags:
--admin_console_server= --port=8081
Python command: /usr/local/bin/python2.7
Open the GAE launcher preferences and set the Python Path option to the fresh installed Python 2.7, in your case /usr/local/bin/python2.7 .
Came across this question looking for a solution to the same dilemma regarding Mac, GAE and Python.
One comment I would like to make regarding setting the Python path using GAE Preferences. I notice you mention that you had a problem setting the Python path using the Preferences. I discovered that after editing the path, you have to press Enter. Otherwise, the path doesn't get updated. This might explain the weirdness you were mentioning when trying to edit the path field.
I installed python 2.7.x from macports. I see this:
$ python --version
Python 2.7.2
$ which python
/opt/local/bin/python
So, in the preferences for GoogleAppEngineLauncher.app I set the python path to:
/opt/local/bin/python
In the console log, I see this:
*** Running dev_appserver with the following flags:
--admin_console_server= --port=8081
Python command: /opt/local/bin/python
I still see some errors about libraries, in particular Can't open zipfile...setuptools but simple stuff at least seems to work.
Good luck!
I am not sure if it helps, but instead of using the binaries from Python, I used MacPorts http://www.macports.org/ and installed the Python 2.7 runtime:
sudo port install python27

Resources