I have been learning a lot of python recently using sublime text on a mac, I installed python 3 and have mainly been using that but as a lot of documentation is in python 2.7 and it comes with the Mac I decided to start using 2.7 instead. I have quite a few libraries installed (for python 3 and for 2.7) When I load my terminal it takes a good 15 seconds for it to get to the prompt and it takes the same amount of time to build python 2.7 from sublime text before it starts executing the code.
I know this post is probably too vague but if anyone has had a similar experience or could suggest anything to point me in the right direction I would really appreciate it.
Thanks.
Run python -vvv to dump out imports Python is doing when it starts up. If the slowdown is by a third party library this should give a hint.
Check your ~/.bashrc script for duplicate entries (see comments below).
Related
I am unfortunately an absolute beginner in programming.
First of all, I'm programming with the PyCharm IDE on a Windows computer, but the script will later run on a RaspberryPi.
I want to turn on my TV with a Python script via HDMI-CEC and I came across libcec.
However, I can't figure out the setup instructions for Windows.
https://github.com/trainman419/python-cec
Can anyone give me a step by step guide on what exactly I need to do to use the CEC commands in Python?
Or should I program with PyCharm directly on the RaspberryPi? This one is way too slow for this task in my opinion. Then I could install the CEC library very easily.
Thanks for your help.
I would like to upgrade my Python version from 2.6.6 to the newest version of 3.6.5 on a server. However, there is a program that has been running for multiple days and will be running for a week or more.
Will my program continue to run until it finishes if I upgrade my Python version?
P.S.: I ran my Python program with the screen command so I wouldn't have to stop it to be able to upgrade my Python version.
Yes, your Python 2 script should continue to run while you install/upgrade Python 3, since Python 2 and 3 are different programs.
However, the installation will be be platform specific and there might be common dependencies, so I would test this on a different machine (e.g. local virtual machine) first.
Several aspects are to be considered here:
In general, a Python program that is running does not access the installed binaries of the interpreter anymore. Also all the modules already loaded will not be read again from disk during the execution time of this program. (In this aspect it differs from e. g. a Bash script which reads its script source while executing.) So you probably are safe in even removing the complete Python installation; of course that's not what you plan on and I wouldn't recommend it for other reasons, but even that should not influence your running Python program. If, however, your running Python program tries to import a module for the first time after the removal or upgrade of your Python installation, this might fail due to incompatibilities between the versions. Most programs do their imports only at the beginning of their runtime, though.
Python 2 and 3 are different languages. Scripts for the one need to be at least adjusted to run with the other. Adjustments aren't too hard to do, though. Most distributions have both installed side-by-side. Most of the time, Python2 is still standard (and accessed by typing python). python2 and python3 are then to make it explicit. This means that you probably should not remove Python 2 from your system, even if you plan on installing Python 3. There probably are scripts relying on the installation of Python 2.
There's a lot going on here that you've not explained/described, so it's hard to give you a definitive answer (such as the operating system you're using). This is also not exactly a programming question, so you might find that the question gets voted to close. That said...
It possible to run multiple versions of Python side by side. Because 2.x and 3.x are very different, it might be much better to have both versions installed. See this answer for some details on doing that:
Official multiple Python versions on the same machine?
It's likely that your code will need some modifications to run on Python 3, so you're going to have to redeploy a new version of your code at some point anyway.
I'm trying to use a github project (TIA), which is dependent on Python 2.7. However, all of the scripts I'm using in the main project are written to run on Anaconda 3 (Python 3.x).
Is there a way for me to run TIA on Python 3.x, even though it says its 2.7 dependent? TIA pulls financial data from Bloomberg's API, and what I'm trying to do is hand that data off to my Python 3.x scripts.
Appreciate any insight on how I should be accomplishing this!
Is there a way for me to run TIA on Python 3.x, even though it says
its 2.7 dependent?
Short answer: no.
Long(er) answer: yes, but you'll have to either adapt the source-code yourself, find someone who has already done it (maybe there is some Python3 compatible fork on Git?). Or you might run python 2.7 to execute the code and write a Python3 script that transforms the output into an acceptable form.
If you are willing to update the source code you could of course use Python2.7's 2to3 module, of which the documentation is found here. Do not expect it to generate a flawless result however, but it might smoothen the ride..
I very recently wrote a program for a friend where it simplifies some important daily calculations for him/her. Now, the problem I am having is that I want to compile the code into an executable program so that he/she can comfortably run it on their machine, perhaps with a simple graphical interface or whatnot.
I have tried using cx_Freeze with Python 3.3.0 64 bit but to no avail (the program simply refuses to start on their machine; I even tried generating an executable via 32-bit Python, but also to no avail). What I then thought was that I could perhaps generate an executable program via PyGame? But the fact of the matter is that I have never used any Python-related program except the IDLE, so I am not sure what to do and look for.
Another option would perhaps be to convert the Python 3.3.0 code to Python 2.x, but the problem is that I am not familiar with Python 2.x and neither is there any automated converter available (as far as I know). I was wondering whether anyone of you could direct me to any good sources/links, since those I have been ferociously Googling are rather inconcrete.
You could just use py2exe. It is compatible with python 3. I have seen tutorials for it on youtube.
You could try embedding it in a C program, and compiling that for your executable. A decent tutorial is in the python docs at http://docs.python.org/2/extending/embedding.html
PyInstaller "is a program that converts (packages) Python programs into stand-alone executables, under Windows, Linux, Mac OS X, Solaris and AIX" and gives you one standalone executable file.
Even as a noob Python user I have succeeded to pack my app using PyInstaller (relatively) easily.
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?