I have been trying for 3 days now with now luck, I really am desperate.
I have installed NumPy, along with matplotlib. I am trying to include matplotlib into my applications, but it does not work. I am using Eclipse with the PyDev plug-in, but whenever I try to import it, I get an error, even though I have added it to the libraries that it needs to import every time.
I am a beginner with Linux and I don't really know how to do stuff of the top of my head. I would like to know if this is related to PYTHONPATH and if so, how can I change it?
Also, when running whereis matplotlib, I get matplotlib: usr/share/matplotlib.
EDIT
Even though I did not manage to solve the problem, nor am I interested any more, I consider this question closed. I have decided to use the free version of PyCharm, as suggested by #FooBarUser.
On my Ubuntu 12.04, modules like these are installed in /usr/local/lib/python2.7/dist-packages. Adding that to PYTHONPATH may help resolve the issue.In my ~/.bashrc I have
export PYTHONPATH=...
export PYTHONPATH=/usr/local/lib/python2.7/dist-packages:$PYTHONPATH
export PYTHONPATH=
Edit: if you also have Python 3 installed on your system, numpy might also be in
/usr/lib/pyshared/python2.7/numpy
If the latest version of numpy was built to be backwards compatible with both 2.7 and 3.*, the installer might put it in that directory which is meant for packages which can be shared across multiple python version numbers.
Related
When I start typing a line, for example plt.subp it will show suggestions from matplotlib.pyplot, if I have imported the library above. This is the expected behaviour. The problem is that this is not happening with numpy. For example say I want to write np.linspace; while I am typing, at no point in time it will show me the the dropdown menu with suggestions (e.g. when I write np.l I should get suggestions like log, log10, linspace, logspace, etc, but that does not happen). The weird thing is that after I type for example np.linspace(, Jedi will show me all the relevant information about linspace.
The setup:
I am trying to set up VSCodium as a python IDE.
In order to isolate the problem as much as I can, I have created a virtual environment and I use this as my Python Interpreter. I have installed a few libraries in the virtual environment, including numpy. I use Jedi as my language server. I have also installed the Python Extension.
Am I missing something obvious here? Do you have any troubleshooting suggestions?
Notes:
When I used anaconda as my interpreter, everything worked as expected. I have other issues with anaconda so I do not use it anymore.
When I use /bin/python as my interpreter this problem appears as well (I numpy installed in my system as well).
This is only happening in VSCodium. If I open a .py file with gvim for example, everything works as expected. This would be irrelevant as vim uses a different LSP (vim-lsp/asyncomplete/pylsp-all), but the weird thing is that when I used vim outside of the virtual environment, I would not get autocomplete suggestions for any imported module, although I would get suggestions for internal python commands. Vim/Gvim also worked as expected with the conda base activated.
Workaround
Using pylance instead of jedi solves the above problem. But this is not a solution of course.
The similar issue has been solved on github.
The solution is that install jedi-language-server in your Python environment (system Python, conda, homebrew, etc) and update your settings.json with the path to your jedi-language-server executable. Example:
{
"jedi.executable.command": "/PATH/TO/JEDI/LANGUAGE/SERVER"
}
By the way, Pylance is really a good choice.
I'm new to coding and I was wondering if someone could explain what exactly python interpreters/environments do and the how that relates to the python versions and packages that can be used in certain projects.
I was trying to code a twitter bot with python and I use VS code as my IDE. While trying to import tweepy into my python code, I noticed I kept getting an error that it couldn't import. After some googling I realized it was because I had to set the python interpreter of the python file to the one that had tweepy installed to. So I changed it and the error with tweepy was solved. But I noticed that I have a bunch of python interpreters in seemingly different locations (screenshot of the interpreter options I'm given). The interpreter that fixed the issue was the one in the pyenv path.
I had installed pyenv some months back because I wanted my terminal (I'm on macOS) to automatically launch python3 when I typed python into the terminal. However, I don't really know what it does beyond that.
So my questions are:
Why do I have multiple python interpreters? Is there a way to get rid of the ones and just keep the one from pyenv (like clean up the ones in /usr/local/bin/python3, /opt/homebrew/bin/python or /usr/bin/python3 since I'm not using them)? or should I not do that?
What exactly does pyenv do? Is it okay that my python libraries are getting installed to pyenv by default? Or should I change it so that it's getting installed to homebrew or one of the usr/bin paths?
Sorry, this is my first time asking a question here so I might not sound that cohesive.
The interpreter is the program which executes a python source file. This is a program like any other, and you can have various versions of it at once (indeed python is quite good at being self contained, and multiple versions will live alongside one another quite happily).
Macs ship with an outdated python 2, used for something in the system. If you remove or update it, things may break. So you install your own python 3 somewhere. If you want to load the new python when you type python in a shell, that shell's $PATH needs to point to the right python. You generally set this in something like ~/.profile.
Pyenv is a tool for managing multiple python interpreters. It's usually used on a per-project basis, to test code against multiple pythons. Further to complicate things, it's often used alongside a virtual environment tool like pipenv. Using it to avoid manually fiddling with $PATH is fine, but a slightly orthogonal use case. All pyenv does is to put little scripts with the same name as python executables somewhere in your $PATH where they supercede anything else. These scripts then figure out which python should get called in this case. So pyenv isn't installing anything, it's just working out which python is going to do it.
The solution to all your problems turns out to be quite simple:
python -m pip install abc
Get into the habit of installing stuff with the python you want to use already set up in the shell, and calling pip like that. That way whatever you use it will always be installed in the right env.
Yesterday I've been trying to install Python 3.8.5. I got the installer from the python website. My problem is that whenever I run python --version in the command line, it keeps saying, like in the image above, Python 2.7.17.
Today I also installed the Microsoft store package, and it's the same.
But running py apparently gives me the correct version 3.8.5. Does this mean that every python program I'll write will use the current version? That's what I currently want to make sure of.
As a side note also, I uninstalled all other python versions except 3.8.5 that I saw in my settings>Apps list. So, that adds to my confusion why running python --version would still show 2.7.17.
Maybe not as relevant, but I also have WSL2 enabled on my machine, I would like to install python to both. At the moment I'm focusing on the Windows10 part, but if there's a solution that will help both, that'll be awesome.
Thanks in advance!
[update]: adding python3 --version screenshot
[update]: yet another confusing part for me:
should I just let this be?
Is this something I need to straighten up first before moving forward?
are my python programs going to be ran in version 3.8.5 and not
2.7.17?
I know my answer is very late but i see a lot of people facing this problem. So if you want to interact with the latest Python version in your command prompt, you just need to set newer (or which one you want) Python path variable above/before other Python version's path variables. This solution also helped me a lot with other path problems.
This is a problem with your PATH environment variable being set incorrectly. I'm guessing that you installed Python 3 globally, after you had Python 2.7 installed. Whenever you do this and have the option Add to PATH checked, it will overwrite the default python location to the new install, thus causing Python 3 to now open instead. You can change this back manually by changing the value in PATH.
I'd suggest using something like pipenv to manage your python versions and respective libraries, that will create a sandbox for your application to run in and will always point to the correct dependencies.
Ok, so hopefully this fixes every question I had. Hopefully comments will assure me that is so.
What I did was, delete the environment variables relating to Python 27. Found the Python3.exe path and added that to the path variable. Not exactly sure how that works, but it did give me the outcome I wanted to see.
I have two python versions on my computer 2.7 and 3.4.1 . I have tried to install numpy by pip3.4 which resulted with vcvarsall.bat not found which i am pretty sure it is included in system path. Then i gave up downloaded numpy binary numpy-1.8.1-win32-superpack-python3.4.exe. And during the installation it tells me that numpy cannot find python 3.4 in the registry which i see that it is there also.
HKEY_LOCAL_MACHINE
-SOFTWARE
--Python
---PythonCore
----2.7
-----Help
-----InstallPath
-----Modules
-----PythonPath
----3.4
-----Help
-----InstallPath
-----Modules
-----PythonPath
so what has left me to do from here? My system is windows 7 64 bit.
There is an easier fix, remove and re-install python, in the beginning of python setup when you are asked if you want to install python for all users or just this user, select this user only.
That way the registry goes into current user by default and can be found easily by successive software packages. Tried it myself, worked like a charm.
Just a simpler option for technologically less literate people like myself.
But if you need it for multiple users on a PC then you have got to edit the registry and put it in manually, from local machine to current user. Copy it like explained in previous comments.
When installing numpy on Windows you have to ensure that you are using a .exe for the corresponding Python installation.
As you're using Python 3.4.1 you have to use an installer for Python 3.4.1. The installer that you were using was last modified on 25th March which is before 3.4.1 was released. This suggests it was for 3.4.0 and so will not work.
If you need up-to-date Windows installers for numpy (as well as a large host of other packages) they can be found here.
This steps work for me with windows 8.1 64bits
The problem is that some module installers look in the wrong place for Python version information.
For example, in the case of this one module, the installer was looking for HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\3.4 in the registry.
I found that my Python 3.4 installer had placed this information in HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\3.2 instead.
Once you know the reason, solving it is easy.
Open Registry Editor (may need administrator privilege) and export HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\3.4 into a text file.
Open the exported .reg file in a text editor and replace the HKEY_LOCAL_MACHINE entries to HKEY_CURRENT_USER.
Add these new entries back to the registry (here is how).
The module installer should now be able to proceed without throwing the error.
ref: http://codeyarns.com/2012/04/28/python-version-not-found-in-registry-error/
I have just faced a similar issue ("numpy cannot find python 3.4 in the registry") when installing numpy-1.9.1-win32-superpack-python3.4.exe. The solution was to install the python-3.4.2.msi instead of python-3.4.2.amd64.msi.
You are trying to install the 32 bit version of numpy on a 64 bit installation of python. It doesn't look to me like you can download 64bit scipy from sourceforge so a solution is to install a 32bit version of python.
Abilio Faria gave the answer. Another answer in another thread over here
I think the changing of the registry works quite well.
Worked wonders for me... quick fix:
http://codeyarns.com/2012/04/28/python-version-not-found-in-registry-error/
I am having trouble installing matplotlib on mac os 10.6, so I used macports and installed all dependencies it needed, which is great, but on top of it a new python version. Now I have two python versions and that bothers me. The matplotlib is working fine on the macport python, and the rest of my stuff is with the default python.
What is the best solution for integrating both into one, and which one to use as the default python?
I tried copying all packages from my default python /defaultPython/../site-packages into the /opt/../site-packages. Same thing would be to add /defaultPython/../site-packages on the PYTHONPATH of macports python.
Some did work fine, but not all.
For example on
import scipy.sparse
I got this error
import _csr
ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/sparse/sparsetools/_csr.so, 2): no suitable image found. Did find:
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/sparse/sparsetools/_csr.so: no matching architecture in universal wrapper
Any thoughts or dirty fix for this?
Thanks a lot!
You should never remove or alter the system Python that Apple supplies with Mac OS X -- that's the specific build they've tested their OS with, and you really don't want to break that.
If you want to use handy macports-installed extensions, you need the macports version of Python for that purpose, so you can't remove that either.
There is no real reason to worry because you have more than one Python version on your system (I typically have at least half a dozen on mine;-).
Just put /opt/... (wherever macports keeps its bin directory) at the start of your PATH environment variable (e.g. in .bashrc) and make sure you install with the macports Python any extension you need there.