Two Pythons: cannot import from within Sublime, works in Terminal - python

I don't know why after a year this suddenly became an issue, but I pip-installed requests and I got an import error when running from Sublime, but it worked fine in the terminal.
I dug a little and found that the terminal was running Python 2.7.3 from /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python (where requests worked) and Sublime was using 2.7.2 from /usr/bin/python. That's where my know-how ends, and this is an area I'm reluctant to fiddle with if I don't know what I'm doing. I'm using OSX 10.8.2. Any suggestions? Not even sure what to Google.

Since you are using a newer, non-system Python (which is a good idea), you need to tell Sublime Text 2 to use that Python. Although your shell $PATH was modified to include the location of the newer Python, Sublime Text doesn't know about that. See this answer for various ways to do that.

You need to start using virtualenv and virtualenvwrapper when developing. It gives you a sandboxed python environment for each of your projects.

I was led to this question/answer (by the above Ned Deily, no less) that solved everything. Hope it helps someone else! (Ned, would love to give you the karma, but at 26.7k it doesn't look like you're in dire need).
How to uninstall Python 2.7 on a Mac OS X 10.6.4?

Related

Why are there so many instances of Python on my system? Which one of these is my system actually using?

I'm using a Mac and this is a screenshot of the files in my /usr/local/bin
This is a screenshot of the files in /opt/homebrew/opt
I'm wondering why I have this amount of Pythons on my Mac. I feel like it's cluttered and confusing. I am also aware that the Macs have a built in Python so just to be clear, I'm not trying to get rid of that. What makes this confusing is that I don't know which Python is in use to update. Typing python3 --version returns 3.9.5 when the latest is 3.9.7. Furthermore, I thought that I had updated my Python through the official website, but found out that I just updated the IDLE that downloads when you install Python from Python.org.
Although a seemingly trivial question, any feedback and knowledge would be appreciated!
The command which python at the terminal will tell you the path of the command python. It might be a symlink so use ls -l on that path to check.

Getting Pip working in PyCharm on MacOS 10.14.5

I'm a python noob working through this intro to python: https://www.youtube.com/watch?v=rfscVS0vtbw. (definitely no need to watch this. Just adding it as context)
It's been going really well, except now I'm up to the part where I need to use pip, and despite having downloaded version 3.8 of Python, it keeps telling me that it doesn't even have pip installed.
I'm wondering if anyone could walk me through what the issue might be and how to actually start using pip in PyCharm.
I've tried downloading pip and installing it but even that doesn't seem to work. If anyone has an ultra-hand-holdy solution (very much for a noob) that would be appreciated.
I feel like the problem might be that I'm putting things in the wrong directories or something? Obviously there are some built-in versions on Python (2.x) already on the Mac so maybe they are interfering?
Thanks in advance for your help.
If I recall correctly, the version of Python that is used when you use the command python is the 2.x version, which doesn't have pip. So if you want to use python in terminal, you should call it as python3 and pip3 for using the pip command.
If you want to set a different Python version as the default one, you can do that. Here is a tutorial that can get you started with that (there's a plethora of other tutorials if this one isn't clear enough): https://opensource.com/article/19/5/python-3-default-mac
For using PyCharm specifically, you can setup the Python interpreter that is used with PyCharm by going to Preferences(or Settings) -> Project:[name of your project] -> Project Interpreter and then chose the desired Python Interpreter from the drop down menu. You can also create a virtual environment there by clicking on the cog icon and choosing Add. This is the preferred way and very convenient to keep installed packages local to your project. After you're done with that, open up PyCharms terminal (at the bottom of your PyCharm window) and you should be able to normally use pip with the command pip.
Alternatively, you can install Python packages in PyCharm using their built in package manager that you can find in the same window where you set your Python Interpreter. Below the dropdown menu you'll see a + sign, where you can click to add packages.

How to change python's "full name" (something like `cpython-34m-x86_64-linux-gnu`)?

I installed Python 3.5 from source and broke a number of modules on Python 3.4, which unfortunately, was an essential part of Ubuntu. I've been trying to fix the system, now I'm almost there, with (hopefully) the last problem: My Python 3.4 only recognize C modules with name *.cpython-34m.so, while all packages from Ubuntu repository are named *.cpython-34m-x86_64-linux-gnu.so. It seems that the cpython-34m stuff is the full name of Python, so I need to change it in accord with Ubuntu's expectation. How can I achieve this?
What you are trying makes no sense. The name cannot be changed, for a good reason. The reason the names are different is to prevent incompatible versions from mixing up each other. You can compile a different version with different options and then the name will be different, too.
The essence of the package management is to satisfy all dependencies through the repositories. Theoretically there should be no need to install anything from the sources.
If you need a different Python version for some specifical reasons, virtual environments would be the thing to look for:
http://docs.python-guide.org/en/latest/dev/virtualenvs/
I reinstalled Python 3.4 via Ubuntu package system, and suddenly everything worked fine. I still have no clue how Ubuntu customize its own Python, since Python's configure command has no related option at all. Anyway, it works, so why bother :P. Finally, thank you for helping me with this problem.

Komodo IDE wont see my Python Modules

I hope it is just that I am doing something stupid but for some reason Komodo wont see a modules I have on my machine. I used PIP to install paramiko and it installed fine. From a terminal the builtin python and ipython will see and import the module fine. When I am trying to write a Python script and I try to import paramiko, Komodo thins its not there at all. I am not sure what to do to fix this.
I did instal some other items from pip and Komodo sees them right away but for what ever reason it wont see paramiko. I will try this on Windwos and Linux to make sure its not just my setup. I hope someone can help me out on this.
I am using the Komodo editor under Linux, so I hope I am not pointing you to a place that does not exist in the IDE, but I hardly doubt it.
So, have you tried adding the module in Komodo:
preferences --> languages --> python --> additional python import directories
This might work.
Joren basically got it but I added the entire "site-packages" folder to Edit (Komodo on OS X) > Preferences > Languages > Python: Additional Python Import Directories, reason being that I hit the issue with other modules.
You shouldn't need to do that obviously. There is a bug filed and it should be fixed soon: http://bugs.activestate.com/show_bug.cgi?id=99829

Best way to have full Python install under cygwin/XP?

Pythons installed under WinXP have dirs like DLLs, DOC, include, etc. but python (2.5) installed with cygwin is a bare python.exe. My motivation for asking is that 'things' under XP don't seem to be finding 'other things' under cygwin and vice versa, I want to start developing with Qt, I like shells, and I do not like MS; I thought if I got all the components under one roof, I could finally start to have scripts find executables which could find files and such. 1. Can I simply copy the contents of an XP installation into the cygwin tree? 2. Is the XP flavor of Python different from the cygwin flavor? (Same CPU, he pointed out, naively.) 3. Someone must work with a full-fledged (if snakes had feathers...) Python from within cygwin; how is it done?
Disclaimer 1: I have never compiled anything under XP or cygwin; had hoped not to have to go there, hence, python in the first place. Disclaimer 2: sorry if this is a ServerFault question, but they seemed to be system people over there and this is (in my case) a lowly desktop.
I use Python from within cygwin, but I don't use the version that cygwin gives you the option of installing as I don't have the control over version number used that I need (we use an older version at work). I have my python version installed via the windows installer (the xp version as you put it) and add the /cygdrive/c/Python2x directory to my PATH environment variable.
Well, in my windows environment I use active python and it, so far, works for me.
Just a little off the question, but...
Have you considered running Sun's VirtualBox with Fedora or Ubuntu inside of it? I'm assuming you have to / need to use windows because you still are, but don't like it. Then you would have python running inside a native linux desktop without any of the troubles you mentioned.
And if you want something that is really easy and portable, then just use Python on Windows, not mixed in with cygwin.
$0.02
This probably has little value, but... I found myself in this exact situation -- we use ActivePython2.5 in production (pure windows environment) and I was trying to do my development within cygwin and cygwin's Python...
After ripping out half of my hair, I have now switched over to Console2, gvim, iPython and ActivePython2.5.
I'm less than thrilled dealing with Windows tools (and their concomitant warts), but at least I'm not getting in my own way when it comes to development. For a while I found I was spending more time trying to get my tools to play nice than actually getting any work done.
Good luck on this one.
I accidentally stumbled on this - If I launch Cygwin from the Cygwin.bat file (which is present directly under the main folder), I get access to the Python version installed under Cygwin (i.e 2.6.8)
If I instead launch the Cygwin from bash.exe under bin directory (C:\Cygwin\bin\bash.exe for me), running "Python -V" shows that I have access to 2.7.3 version of Python (that was installed for Windows).
So, I guess you can do the same.

Categories

Resources