I am struggling with getting pygame to work on VS Code. The only thing that seems to be amiss is that these are different versions and they are in different folders:
PS C:\Users\rebec\My Drive\VS Code\Python Config> python --version
Python 3.9.11
PS C:\Users\rebec\My Drive\VS Code\Python Config> pip --version
pip 22.1.2 from C:\Users\rebec\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pip (python 3.10)
I have tried uninstalling and installing pygame. I think it's something with the file configs but I just don't know how to fix it. Thanks in advance for the help!
You have two versions of python installed on your computer. One is 3.9.11, and another is 3.10. You installed pygame for python 3.10, and tried to run it with python 3.9.11.
If you want to run your game using the global interpreter (python 3.10, the one where you installed pygame), you will need to switch your interpreter inside VSCode:
Press Ctrl+Shift+P to open a command pallete.
Open Python: Select interpreter.
Set your interpreter to global one.
You might also want to consider using a virtual enviroment to avoid problems like these in the future:
Each virtual environment has its own Python binary (allowing creation of environments with various Python versions) and can have its own independent set of installed Python packages in its site directories, but shares the standard library with the base installed Python.
Related
enter image description here
Somebody please explain why I am not able to import package in VSCode even though I can do it in terminal both in VSCode and in system
Check out https://code.visualstudio.com/docs/python/environments
VSCode uses multiple python binaries. Each one has a seperate list of installed modules and packages. By default VSCode uses a custom Anaconda binary. When you invoke the python command, you are using a system wide install of Anaconda. You need to change the binary version of python VSCode is using, to point at the system-wide install, where you installed your modules
I have a specific problem with python. I have on my ubuntu two versions python3.4 and python3.6(from anaconda). I want use just anaconda pythoncurrent version
But when i run script i have some problems with another python version
another version
How i can safe delete useless python 3.4.6?
sudo apt-get remove python3.4
anaconda should have set python3 as default python3.6 version
You should probably not delete Python3 from your system, even if you have Anaconda installed, since there might be system software that:
was not tested with subsequent versions of Python;
might struggle finding Python from Anaconda.
What you should do instead is configure your IDE / environment to run Python script with Anaconda, e.g. by setting your PATH variable to point to your anaconda/bin directory or similar.
If you are using PyCharm, as it seems from the screenshot, you could set up your project to run the Anaconda Python without modifying your other command-line settings.
I was required to install anaconda for a CS course and used spyder and Rstudio.
Then, for a different class I used pycharm.
When I type on the command line "python -V" I get:
Python 3.6.1 :: Anaconda 4.4.0 (x86_64)
and I have no idea why it relates the python version I have installed with Anaconda (and why not pycharm?). I understand that the OS runs python 2.7 (shouldn't I get that instead? and when I type python3 -V get which version of python 3 I have?) and when I use something like Pycharm or Spyder I can choose which version I want from the ones I have installed and use it within the program, not for the terminal.
I just want to have everything in order and under control. I don't think I understand what Anaconda really is (to me is like a program that has more programs in it...). How do I keep anaconda to itself ? 1313
Also, should the packages I installed through Terminal work on both pycharm and spyder/anaconda even though when I used pycharm I used python 3.5 and anaconda 3.6?
I think I need definitions and help to get everything in order in my head and the computer.
Pycharm is just an application to help you write code. Pycharm itself does not run python code. This is why in PyCharm, you need to set the interpreter for a project, which could be any python binary. In PyCharm, go to Preferences > Project > Project Interpreter to see where you would set the python environment being used for a given project. This could point to any python installation on your machine, whether that is the python 2.7 located at /usr/bin/python or a virtual environment in your project dir.
The industry standard way to "keep things in order" is to use what are called virtual environments. See here: https://docs.python.org/3/library/venv.html. A virtual environment is literally just a copy of a python environment (binaries and everything) so whatever directory you specify. This allows you to configure your environment to however you need in your project without interfering with other projects you might have. For example, say project A requires django 1.9.2 but project b requires 1.5.3. By having a virtual environment for each project, dependencies won't conflict.
Since you have python3.6, I would recommend going to you project directory in a terminal window. Running python -m venv .venv to create a hidden directory which contains a local python environment of whatever your 3.6 python installation. You could then set your project interpret to use that environment. to connect to it on the command line, run source .venv/bin/activate from where you created your virtual environment. run which python again and see that python is now referencing your virtual environment :)
If you are using a mac (which I believe you are from what you said about python2.7), what likely happened is that your anaconda installer put the Python bin directory on your PATH environment variable. Type in which python to see what the python alias is referencing. You can undo this if you want by editing your ~/.bash_profile file if you really want.
You are more or less correct about anaconda. It is itself another distribution of python and contains a load of common libraries/dependencies that tend to make life easier. For a lot of data analysis, you likely won't even need to install another dependency with pip after downloading anaconda.
I suspect this won't be all too helpful at first as it is a lot to learn, but hopefully this points you in the right direction.
I have Python 2.7.8 installed and when doing the version check in my command line, it shows that I have Python 2.7.8.
However, when I run PyCharm it's running it on version 2.6. Is there a way for me to get it to make PyCharm take the 2.7.8 version?
Thanks for the help!
By default, PyCharm picks up the Python installed system-wide.
Which Python your project should use is configured under Project Interpreter section of your Project Settings. From there, you can add existing interpreters either locals, or remotes, even create brand-new virtual environments and manage packages inside.
I'm using mac OsX 10.8.2, pyCharm 2.7.1. python 2.7.2
I want to use pygame package with pycharm. I followed the instructions on the pygame site and installed pygame 1.9.1 successfully.
When I write "import pygame" pycharm doesn't find the package.
I tried installing the latest updates of python, pycharm and pygame. I tried using the "install" window in the preferences. It installed "pygamess", "pygameui" and "pyviewx.pygame", but when I try to instal "pygame_loaders" it writes "Install packages failed: Error occurred when installing package pygame_loaders".
If you can please give simple instruction since I'm not a heavy mac-user.
To use pygame under OS X, you need to run Python under the 32 bit interpreter. It's usually called something like 'python2.7-32', and if installed from the package on http://www.python.org/, within /usr/local/bin
To get this working in PyCharm, open a project, then preferences ('apple'-'comma'), go to 'python interpreters', and click the '+' button in the right hand pane.
A list should appear and you'll see '/usr/local/bin/python2.7-32', select that and then make it the default for your PyGame project.
If you haven't installed Python from python.org, I recommend you do so; the current version is 2.7.3.
The above setup is how I got PyGame working in PyCharm on Sunday, so it should still be valid.
If you have a 2.7 virtualenvs running inside pyCharm you can manual install pygame.
Navigate to the virtual env on you disk via the terminal:
cd ~/.virtualenvs/Pygame
Or whatever directory you have. Now we active the virtualenv, just like we normal do when we not work inside pyCharm.
source ./bin/acivate
You should see something like this
(Pygame)mbp-2:Pygame pietje$
Now we can install pygame inside this env.
pip install hg+http://bitbucket.org/pygame/pygame
That's it and everything should work fine inside PyCharm. It does work on my machine :)