Pygame/Python/Terminal/Mac related - python-3.x

I'm a beginner, I have really hit a brick wall, and would greatly appreciate any advice someone more advanced can offer.
I have been having a number of extremely frustrating issues the past few days, which I have been round and round google trying to solve, tried all sorts of things to no avail.
Problem 1)
I can't import pygame in Idle with the error:
ModuleNotFoundError: No module named 'pygame' - even though it is definitely installed, as in terminal, if I ask pip3 to install pygame it says:
Requirement already satisfied: pygame in /usr/local/lib/python3.7/site-packages (1.9.4)
I think there may be a problem with several conflicting versions of python on my computer, as when i type sys.path in Idle (which by the way displays Python 3.7.2 ) the following are listed:
'/Users/myname/Documents', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/Users/myname/Library/Python/3.7/lib/python/site-packages', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages'
So am I right in thinking pygame is in the python3.7/sitepackages version, and this is why idle won't import it? I don't know I'm just trying to make sense of this. I have absoloutely no clue how to solve this,"re-set the path" or whatever. I don't even know how to find all of these versions of python as only one appears in my applications folder, the rest are elsewhere?
Problem 2)
Apparently there should be a python 2.7 system version installed on every mac system which is vital to the running of python regardless of the developing environment you use. Yet all of my versions of python seem to be in the library/downloaded versions. Does this mean my system version of python is gone? I have put the computer in recovery mode today and done a reinstall of the macOS mojave system today, so shouldn't any possible lost version of python 2.7 be back on the system now?
Problem 3)
When I go to terminal, frequently every command I type is 'not found'.
I have sometimes found a temporary solution is typing:
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
but the problems always return!
As I say I also did a system reinstall today but that has helped none!
Can anybody please help me with these queries? I am really at the end of my tether and quite lost, forgive my programming ignorance please. Many thanks.

Try it with the problem1
I'm not an expert neither, but I think you need to install both in terminal and python in order to use the program.
python -m pip install pygame

You should actually add the export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" to your .bash_profile (if you are using bash). Do this by opening your terminal, verifying that it says "bash" at the top. If it doesn't, you may have a .zprofile instead. Type ls -al and it will list all the invisible files. If you have .bash_profile listed, use that one. If you have .zprofile, use that.
Type nano .bash_profile to open and edit the profile and add the command to the end of it. This will permanently add the path to your profile after you restart the terminal.
Use ^X to exit nano and type Y to save your changes. Then you can check that it works when you try to run the program from IDLE.

Related

Error--rescode.err_missing_license_file(1008): License cannot be located

I was running a python program which uses CVXPY to solve a optimization problem involving semi-definite constraints. Initially the code ran well when I was using the default solver provided by CVXPY. Then I tried to use MOSEK as the optimization solver. Since it has to be installed, I tried installing it from command prompt using a pip installer. However the installation was interrupted midway (I am unaware of the specific reasons). Now whenever I am trying to run the code, it is prompting an error-
rescode.err_missing_license_file(1008): License cannot be located. The default search path is ';C:\Users\dsouv\mosek\mosek.lic;'.
I can understand that somehow the default search path has been changed due to the failed installation of MOSEK. Even after calling the default solver of CVXPY, I am still getting the same error.
Things I have tried:
Reinstalling CVXPY.
Reinstalling MOSEK from the Anaconda Powershell Prompt.
Even after trying out these, the error still persist. Any suggestions to solve this issue is welcome. Also please me if you need any other informtion.
Thanks
You should install the license file separately. I.e. do step 3 at
https://www.mosek.com/resources/getting-started/

Problem with "import rarfile" in python on Ubuntu

Today I turned on my Ubuntu virtual machine and tried to do a project in Python 3.9.4,
but this one used rarfile module. Which is throwing errors.
I know rarfile uses unrar, and I installed both rarfile and unrar.
Tried to type unrar seperately and it works.
I almost spent whole day trying to figure this out.
My question is why does importing rarfile module not work, and how can I fix it.
I also read online it could have something to do with PATH, but I am pretty new to linux and don't know terminology of it and therefore don't know how to try to fix it.
Some information regarding that would probably help if not now, for the future problems regardless if it is connected to this problem or not.
Sorry if I formatted this post poorly, it's my 2nd post on here.
I would do pip install rarfile to make sure it is install
also you may want to do a pip list to make sure its intalled.
Also if python 2 is install then most likly you need to do pip3 install rarfile.

Can anyone help me installing PYPY on windows?

I would like to know the more brief version of the installation of pypy on Windows apart from original documentation available on https://doc.pypy.org/en/latest/windows.html. Any help in showing a step by step guide would be appreciated. Thanks in advance.
The link you referenced is about building PyPy from source, so the parallel in CPython would be https://devguide.python.org/setup/.
The vast majority of users (99.99%) will not want to do this. They want to use PyPy as an interpreter to run python code, and should be looking at the (agreed, too-long) instructions on the download page. Specifically,
download the zip file, and extract it somewhere. Explorer suggests C:\Users\matti\Documents\pypy3.6-v7.3.1-win32 for me, that is fine.
Next set up the new pypyp interpreter by getting pip and setuptools installed. Click on Start and type "cmd" then click on "Comand Prompt" to open a text terminal. Once there type <path\to\pypy> -m ensurepip, so for me that would be C:\Users\matti\Documents\pypy3.6-v7.3.1-win32\pypy3.6-v7.3.1-win32\pypy3.exe -m ensurepip which should print at the end Successfully installed pip-20.0.2 setuptools-44.0.0
Open a new file in VS Code, and click on the "Python" at the far left of the status bar (bottom left corner in my default VSCode layout), and choose the path to pypy3.exe as the one to use for this file.
I think that is it? You may want to let VS Code install things like a linter or other tools, that is fine.
PyPy is also available via Conda, which is slowly building out all the packages specifically for PyPy: Numpy, Scipy and others are already available, matplotlib should be coming soon.

Anaconda install on Windows is stuck on executing install.py

Update: Two months after posting this question, I switched to a fresh install of Windows 10 and was able to install the correct version of Anaconda Python. Unfortunately the answers came too late for me to test them.
I want to switch from the 32-bit version of Anaconda Python 3.5 to the 64-bit version. First I uninstalled Anaconda through the 'Programs and Features' window, then I downloaded the Anaconda3-4.2.0-Windows-x86_64.exe installer and attempted to run it. For reference, I am using the 64-bit version of Windows 7. After some initial processing the installer is stuck on Execute: "C:\Users\user.name\AppData\Local\Continuum\Anaconda3\pythonw.exe" -E -s "C:\Users\user.name\AppData\Local\Continuum\Anaconda3\pkgs\.install.py" --root-prefix "C:\Users\user.name\AppData\Local\Continuum\Anaconda3" --post root
It does not throw any errors, it just hangs. I let it run throughout the night to see if it would progress any further, but unfortunately it was still stuck in the same place in the morning. Afterwards I tried looking for hidden Continuum files from the previous installation and removed those - also removed Anaconda from my PATH variable. I even tried installing miniconda instead of anaconda, but both installers get stuck in the exact same place. Am I missing a hidden file somewhere which is causing the Anaconda installer to hang?
Below is part of the installation log up until the execution command where it gets stuck.
Installing: dill-0.2.5-py35_0 (into root)
untgz::extract -d 'C:\Users\user.name\AppData\Local\Continuum\Anaconda3' -zbz2 'C:\Users\use.name\AppData\Local\Continuum\Anaconda3\pkgs\dill-0.2.5-py35_0.tar.bz2'
Writing Lib/site-packages/dill-0.2.5-py3.5.egg-info
Writing Lib/site-packages/dill/__diff.py
Writing Lib/site-packages/dill/__init__.py
Writing Lib/site-packages/dill/__pycache__/__diff.cpython-35.pyc
Writing Lib/site-packages/dill/__pycache__/__init__.cpython-35.pyc
Writing Lib/site-packages/dill/__pycache__/_objects.cpython-35.pyc
Writing Lib/site-packages/dill/__pycache__/detect.cpython-35.pyc
Writing Lib/site-packages/dill/__pycache__/dill.cpython-35.pyc
Writing Lib/site-packages/dill/__pycache__/info.cpython-35.pyc
Writing Lib/site-packages/dill/__pycache__/objtypes.cpython-35.pyc
Writing Lib/site-packages/dill/__pycache__/pointers.cpython-35.pyc
Writing Lib/site-packages/dill/__pycache__/settings.cpython-35.pyc
Writing Lib/site-packages/dill/__pycache__/source.cpython-35.pyc
Writing Lib/site-packages/dill/__pycache__/temp.cpython-35.pyc
Writing Lib/site-packages/dill/_objects.py
Writing Lib/site-packages/dill/detect.py
Writing Lib/site-packages/dill/dill.py
Writing Lib/site-packages/dill/info.py
Writing Lib/site-packages/dill/objtypes.py
Writing Lib/site-packages/dill/pointers.py
Writing Lib/site-packages/dill/settings.py
Writing Lib/site-packages/dill/source.py
Writing Lib/site-packages/dill/temp.py
Writing Scripts/get_objgraph.py
Writing Scripts/unpickle.py
Writing info/LICENSE.txt
Writing info/files
Writing info/has_prefix
Writing info/index.json
Writing info/platform
Writing info/recipe/bld.bat
Writing info/recipe/build.sh
Writing info/recipe/meta.yaml
extraction complete.
Execute: "C:\Users\user.name\AppData\Local\Continuum\Anaconda3\pythonw.exe" -E -s "C:\Users\user.name\AppData\Local\Continuum\Anaconda3\pkgs\.install.py" --root-prefix "C:\Users\user.name\AppData\Local\Continuum\Anaconda3" --post root
I simply ended all python processes (any stale anaconda install/uninstall process running) and deleted all directories created during previous installation attempt. Then I could install without trouble.
If above effort does not work, check the environment path variables. It should not include any python path.
I have ended pythow process from taskmanager and removed unnecessary/irrelevant from environment path. It resolves my issues.
Try this, it worked for me:
conda install python=3.5
conda install tensorflow
Temporary disable antivirus and then try.
For me the installation was extremely slow, especially during the "unpacking" phase. After I disabled the "Real-time protection" under "Virus & threat protection" - the installation continued much faster.
I solved this issue by doing the following:
The installation was stuck on "extracting: anaconda-2020.02-py37_0.tar.bz2".
I went to https://anaconda.org/anaconda/anaconda/files and installed that file manually.
I extracted that file in the anaconda folder and it was all good!
As mentioned by ClaraJacintho in https://github.com/ContinuumIO/anaconda-issues/issues/6258#issuecomment-565063685:
I found that the "security module" called Warsaw (or GAS antifraud), used by many banks in Brazil for internet banking security, was interfering with the installation. I uninstalled it and was able to install Anaconda3.2019.10 64 bits on my Windows 10 machine.
It worked for me.

SublimeCodeIntel isn't looking in python 3 paths

I installed SublimeCodeIntel package in sublime text, and I use it to code in python 3. However, the problem is that it uses python2 paths to do the import, so if a library is installed in python2 and not in python3, i won't find it when i use import or from X import y.
I did confirm that when I used the command SublimeCodeIntel: Dump Import Directories , so I saw both the files python and python3 in the directory ./codeintel/import_dir_stats and here is there content :
python
dedeeb56f744e507026fef17243da41f /home/bilal/.local/lib/python2.7/site-packages
6a1d0cac3d9e6148e2208b63a33a1e6f /home/bilal/.local/lib/python2.7/site-packages/impacket
16a4fccbb3beadfdfd72691ef8f7298c /home/bilal/.local/lib/python2.7/site-packages/mechanize
211d2b55059f6b634799fdae534decd9 /usr/lib/python2.7/dist-packages
be5448890caffe81686310f127d6efae /usr/lib/python2.7/dist-packages/_markerlib
cec69a0830a725e10ac4e364d44add8f /usr/lib/python2.7/dist-packages/appindicator
python3
dedeeb56f744e507026fef17243da41f /home/bilal/.local/lib/python2.7/site-packages
6a1d0cac3d9e6148e2208b63a33a1e6f /home/bilal/.local/lib/python2.7/site-packages/impacket
16a4fccbb3beadfdfd72691ef8f7298c /home/bilal/.local/lib/python2.7/site-packages/mechanize
211d2b55059f6b634799fdae534decd9 /usr/lib/python2.7/dist-packages
be5448890caffe81686310f127d6efae /usr/lib/python2.7/dist-packages/_markerlib
cec69a0830a725e10ac4e364d44add8f /usr/lib/python2.7/dist-packages/appindicator
I didn't put all the lines (because there is a lot), but the content of the two files is identical.
I don't understand from where is coming this problem, why SublimeCodeIntel is looking in python2 directories for the import ??!!
PS : I am using Ubuntu 15.10 (with Linux version > 4), and sublime text 3 build 3103.
Please help, I really consumed a lot of time and energy looking for this.
I would strongly recommend using the Anaconda plugin (no relation whatsoever to the Anaconda Python distribution) instead of SublimeCodeIntel. I struggled with SCI for a while on various machines, and could never get very good code completion out of it until I ran across Anaconda one day. The next day I removed SCI and have been completely satisfied ever since. It's super-easy to configure (just give it the path to your python executable and it reads sys.path and all the rest), and pretty much just works. It has linting with several different linters built-in (you can disable them if you want), has popups available for function signatures and other hints, works with virtualenvs right out of the box, and more.
(I didn't write it and I have no connection to the author(s) - it's just a great plugin!)

Resources