Problems with Pygame on MAC OS X - python

I am having trouble setting up Pygame on my MAC. Here are my specifications: OS X El Capitan 10.11.4. Whenever I run a file with import pygame I get the following error message in terminal:
ImportError: No module named 'pygame'
If I try to install pygame from bitbucket that the directions, which I am following told me to do, I get the following message:
-bash: /usr/local/bin/pip3: /usr/local/opt/python3/bin/python3.5: bad interpreter: No such file or directory
Again, that message appears when I run the following command, in terminal:
enter code here pip3 install --user hg+http://bitbucket.org/pygame/pygame
I have tried Youtube videos and stack overflow but nothing seems to help me. I believe, but I am not sure, that I am still pointing to python 2.7 and I have no idea how to fix that. I believe I am using python 3.4. I find problems similar to mine but not sure exactly what to do. Any help would be great! Thank you!

Note, I'm not currently on a mac so I'm doing kind of from memory and what I assume should work so some of this might be different for you.
open terminal and type:
which python3
Copy the value of what the which command returns.
Open up your ~/.bash_profile using a text editor, I think you can just type (but not sure)
edit ~/.bash_profile
and you can add these two lines into your bash profile:
PATH="[Replace me with what the which command returned]:${PATH}"
export PATH
save and then in your terminal window you can type:
source ~/.bash_profile
echo $PATH
python --version
to verify that it's picked up your changes.
A few caveats I can think of are compatibility between things using python 2.x and 3.x, and this could break existing programs, so if you need to change back for whatever reason just delete the lines you added into your bash profile.

I found that the information at this site worked: https://bitbucket.org/pygame/pygame/issues/82/homebrew-on-leopard-fails-to-install

Related

Error occurring while installing and importing pynput

So I am trying to install and import pynput in VSCode but its showing me an error every time I try to do it. I used VSCode's in-built terminal to install it using pip and typed the following :
pip install pynput but this error is shown : Fatal error in launcher: Unable to create process using '"c:\users\vicks\appdata\local\programs\python\python38-32\python.exe" "C:\Users\vicks\AppData\Local\Programs\Python\Python38-32\Scripts\pip.exe" install pynput': The system cannot find the file specified
After receiving the following error, I tried using CMD to install it but the same error is shown. I also tried using python pip install pynput and it shows Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases. even though I have python 3.9.7 and I have selected it as my interpreter in VSCode and I have IDLE(Python 64 bit) installed. How may I resolve the following error? Any help regarding the same is appreciated
Thanks in advance :)
There's no such thing as an in-built terminal in VS code. When you open a terminal in VS Code, it opens the default, which on Windows is usually equivalent to opening up CMD.
If you selected Python 3.9.7 as your default interpreter in VS Code, it does not mean that it will visible to your CMD / terminal. It just means that the VS Code IDE will refer to that instance of Python when launching the program from VS Code itself using the green button (or F5), and when scanning your code to point out missing packages, etc.
CMD will only automatically detect your Python if it's in your PATH environment variable. You should add the Python 3.9.7 base and Scripts path to this.
Also, it would be best if you could first uninstall conflicting versions (like your 3.8.x) of Python and remove them from PATH, assuming that this won't cause any problems for you. Perhaps keep a record all the installed packages in this old version of Python for future reference using pip freeze or pip list.
Check if c:\users\vicks\appdata\local\programs\python\python38-32\python.exe exists by typing cd c:\users\vicks\appdata\local\programs\python\python38-32

Why Python and pip can't be found neither on cmd or in IDE?

I messed up with the files and deleted some 32bit Python files because I thought that they're unnecessary.
Then I discover that they had some interesting files to run some specific modules so I just uninstalled Python and re-downloaded it. When I tried to run pip in cmd and even git bash it shows that Python is not defined even after I added it to path same with pip module, now no code can be executed.
import pygame
pygame.init()
screen = pygame.dis`play.set_mode((800, 500))
What shall I do to fix it?
As you not provide the message, that appears when python or pip is not found, all below is just my speculations about the common mistakes in more or less close cases (as I undertand that).
Programs may be not found as they are not in your %PATH%. To ensure that you need to open new CMD window and issue
echo %PATH%
If there is no signs of folder your Python was installed in the output you'll see - that's the case I'm talking about. Otherwise just ignore all the following part of my answer.
In that case one of the easiest way is to properly uninstall Python and then install it once again. Don't forget to mark "Add to PATH" option during install.

Unable to run ipython notebook or anaconda (conda) commands in terminal

I am trying to get the ipynb running on my Mac, but I am running into some trouble. I specifically want to run the ipynb that comes with Anaconda.
This question is very close to helping me but I am not sure what to do with the results from checking which python, which python2.7, which ipython.
When I type 'ipython' into the terminal, I get
/bin/bash: /Users/me/anaconda/bin/python.app: No such file or directory
Anaconda isn't even located in /Users/me/ so I don't know why bash is looking there when I've put /usr/local/bin/anaconda/bin at the front of my path (which I did after that post suggested I check my path variable).
$ which anaconda
/usr/local/bin/anaconda/bin/anaconda
$ which python
/usr/local/bin/anaconda/bin/python`
$ which python2.7
/usr/local/bin/anaconda/bin/python2.7
$ which ipython
/usr/local/bin/anaconda/bin/ipython
I tried this to see if it worked, because I'm guessing it is related to the problem I am having:
$ conda -h
-bash: /usr/local/bin/anaconda/bin/conda: /Users/me/anaconda/bin/python: bad interpreter: No such file or directory`
From the responses I'm getting from bash, it looks like everything is pointing to where it should be, so then why, when I type ipython or conda into the terminal, do I get those errors?
(Not sure if this is related, but some posts I've seen refer to changing the pip file to point to the version of Python I want, but I am not quite sure where to find the 'pip file'. I went looking for it wherever my pip is stored but I couldn't find a file per say.)
It is most likely looking in the wrong place. Standard installations would be in /Users/username/anaconda/bin. If you have installed it in /usr/local/bin/anaconda/bin/python you will want to be sure it is in you .bash_profile. In terminal run the following:
open .bash_proflie
Add the following:
export PATH="/usr/local/bin/anaconda/bin:$PATH"
Again the usual Path would be:
export PATH="/Users/me/anaconda/bin:$PATH"
Be sure to relaunch terminal or run "source .bash_profile"
I solved this problem by moving anaconda to root ("/")

pip command does nothing

I just installed Python 2.7.10 on windows 10.
I have added my python and pip directory to my PATH like so:
My Scripts folder looks like this:
My problem is, when I type in "pip" in command prompt and press enter absolutely nothing happens, even if I wait several minutes. If I remove the Scripts directory from the PATH variable I just get the error message like "pip not recognized as internal or external command". Python works fine. I have also tried to reinstall both pip and Python but the same problem occurs.
So, does anyone have any idea about why pip does not do anything?
**Edit: ** when I say it does not do anything, I mean the cmd "hangs", like if it is waiting for something to happen. The cursor just keeps on blinking.
One command that is bound to work is writing:
python -m pip install requests
This works because you hand off the script invocation to python, which you know works, instead of relying on the PATH environment variable of windows, which can be dodgy.
Packages like numpy that require c-extensions to be built, will not work with pip unless you have a C Compiler installed on your system. More information can be found in this question.
If you are, as you're saying, unfamiliar with the python environment, then let me assure you, you will have a better day by installing Anaconda.
Anaconda is a completely free Python distribution (including for
commercial use and redistribution). It includes more than 300 of the
most popular Python packages for science, math, engineering, and data
analysis.
Anaconda comes with numpy, of course.
After Python including pip at package, pip commands not work sometimes.
Then you can use pip through python like
python -m pip <pip commands that you want>
Try disabling your virus scanner. If this fixes it, exclude the C:\Python27\ folder from scanning (at your own risk).
I had this same issue: typing pip on the command line just puts the cursor on the next line, and nothing happens. I was sure my PATH system variable had C:\Python27\ and C:\Python27\Scripts\ in it, and I could verify it using echo %PATH% on the command line.
I found that I had to disable my virus scanner (Avast). I excluded the C:\Python27\ from virus scanning, and now everything works. Apparently the scanner is interfering with Python's ability to load the module.
Add the following path or you can also cd to the path and then try pip command, it will work fine.
C:\Python27\Lib\site-packages\pip
I had the same issue after uninstalling my antivirus, which was blocking the script. The issue was resolved.

"ImportError no module named gnuradio" when trying to execute ./uhd_fft

I have followed instructions out lined here:
http://forums.nuand.com/forums/viewtopic.php?f=9&t=2804
and installed GNU Radio from GIT repo (scroll down to the section that says "Building GNURADIO from GIT". I used the ./build-gnuradio.sh script to do this and it took a while, but it appeared to build successfully, as per the instructions.
I am running on Ubuntu 12.04 LTS.
When I attempt to run the "./uhd_fft" function I get the following error message:
Traceback (most recent call last):
File "./uhd_fft", line 23, in <module>
from gnuradio import gr, gru
ImportError: No module named gnuradio
I have Googled this error message and most of the forums claim there is a problem with the PYTHONPATH.
When I do
echo $PYTHONPATH
/usr/bin/python2.7
But when I check the python2.7 directory I do not see gnuradio. So I guess it makes sense I'm getting an import error when it tries to import gnuradio. But the bigger question is why?
I installed GNU Radio (per instructions from nuand forum) using ./build-gnuradio.sh script. So I should have it installed.
I would appreciate if it python / GNU Radio experts from the community could weigh in.
There is a section later in the instructions with this boldface label:
Now for some voodoo to get the new program installed into system libraries and python paths and executable path.
Those instructions lead you through modifying your PYTHONPATH to pick up the gnuradio module, among other things. If you have followed those instructions, you will have to start a new shell to see any effect, or execute the .sh file by hand, since profile scripts only run when a new shell starts up or when they're run manually.
One of the reason for this error is, when the default python is selected incorrectly. To see which python is selected type the following command in the Terminal:
"sudo port select python"
it will display all the python available on your mac.
like:
python26
python27-apple(Active)
python27
For Gnuradio you need python27,if other python is active like in the example above you can change it by the following command:
"sudo port select python python27"
Now RUN your python code,it should work.If python27 is already active you may consider changing the path manually as suggested by others
Try this once the PATH variables have been set.
ln -sf /usr/lib/x86_64-linux-gnu/libvolk.so.1.3.1 /usr/lib/x86_64-linux-gnu/libvolk.so.1.3
On OSX 10.12.3 (16D32) this worked for me:
export PATH=/opt/local/bin:$PATH
python
> import gnuradio
For me python at the prompt was using Mac's python instead of the one in
/opt/local/bin/python
The link you have provided also mentioned that you might need to add dist-packages and site-packages.
The following command solved the issue for me:
export export PYTHONPATH=/usr/local/lib/python3/dist-packages:/usr/local/lib/python3.6/dist-packages:\
/usr/local/lib/python3/site-packages:/usr/local/lib/python3.6/site-packages:$PYTHONPATH

Categories

Resources