spyder won't autocomplete with new interpreter (virtualenv) - python

I apologize first that this seems identical to this discussion. My virtualenv seems to work fine. I would just like to use spyder as an IDE to smooth over my Python deficiencies.
Following the above discussion, I changed the interpreter with
Tools>>Preferences>>Console>>Advanced>>PythonExecutable
and I set it to /bin/python
Great! Works like a charm. However, unlike the case with the default interpreter, Spyder will not autocomplete my code. Normally I am prompted after a period for example.
'Tools>>Update module names'
did not help as was suggested.
Thanks in advance,
Chris

Interestingly this problem was resolved when I installed PySide to the virutal environment. I was alerted to install PySide when I tried to call matplotlib.pyplot from within Spyder

Related

VSCodium Numpy autocompletion not working

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.

Import packages works in idle.exe but not in IDE (python)

Please note that I am a complete beginner and installed python simply by going to the website and clicking "install". It used to work fine.
Now suddenly I have this frustrating situation where I can run just about anything in the idle.exe found in the scripts section of arcgispro, but cannot run the same .py file in an IDE. As a beginner this is obviously a headache as I would like auto code formatting, suggestions, etc. Literally any IDE would be fine (spyder, pycharm). The problem is that every single time there is some kind of error with the package imports. e.g. from pycharm:
import shapefile ModuleNotFoundError: No module named 'shapefile'
It's not just shapefile... this is happened at random times with numpy and also matplotlib.
When I look at "Installed Apps" on windows, it just says Python 3.10.0 and Python Launcher.
No, there is no file that I created called "shapefile.py"
A lot of solutions suggest things with pip... I have absolutely no idea what pip is...is it installed program? where do I find that?
EDIT: I just found out that the system paths of the two are different so this explains why one works but the other doesn't... but how can I make it so that the IDE would work?
Ok, simple answer:
In Pycharm, go to the bottom and click on Python Console. Then type pip install pyshp. Voila! Assuming it works for other packages as well. Still do not know where to make pycharm work with the other environment...

Python versions in my PC shows 2.7.17 instead of 3.8.5

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.

Fake module for autocomplete support Pycharm [duplicate]

When writing Python code using compiled extensions (the OpenCV Python bindings, for example), PyCharm doesn't seem to be aware of their availability. The imports are marked with a grey underline, saying "unresolved reference" as a tooltip, and autocomplete doesn't work, either. (Except for the function names already used in the code.)
This isn't caused by wrong module paths, the code runs without error when started. Also, after I import the modules in a Python shell, autocomplete starts working as expected.
Is there a solution for that or is this an architectural limitation for compiled extensions? Are there any other IDEs that manage to cope with this problem?
The imports are marked with a grey underline, saying "unresolved reference" as a tooltip
This most probably means that PyCharm can't see the module you import. In editing mode, PyCharm relies on availability of Python sources of imported modules. If a module is not written in Python but is a C extension module, PyCharm generates a 'skeleton' that contains function prototypes, and uses it for completion.
In shell mode, PyCharm uses live imported objects for completion, with slightly different results.
Make sure that your OpenCV installation is visible for the Python interpreter you chose for the project (File / Settings / Python interpreter). If the interpreter is correct, try removing and re-adding it (this is time-consuming a bit, sorry).
If nothing helps, file a bug.
I have noticed a difference in pycharm behavior depending on the way to import.
using:
import cv2
the auto completion doesn't work,
while with:
from cv2 import cv2
auto completion works
I had to hardlink the binary into the folder lib-dynload of my interpreter.
$ cd /usr/lib/python3.7/lib-dynload
$ sudo ln /usr/local/lib/python3.7/dist-packages/cv2/python-3.7/cv2.cpython-37m-x86_64-linux-gnu.so cv2.cpython-37m-x86_64-linux-gnu.so
The paths may vary in your environment. I didn't test it on OSX or Windows, but it may work there too. The lib-dynload folder is here:
PyCharm currently does not scan compiled extensions/binaries which are in a path manually added to the interpreter in the IDE. I have filed a bug with Jetbrains in YouTrack. You might want to have a look at it and possibly the discussion I initiated in their discussion forum (link is in the bug description). I'd appreciate if you could vote for this issue to be resolved in YouTrack if you are a PyCharm user facing the same problem.
Try clicking "Reload" button in File | Settings | IDE Settings | Python interpreters. That got it working for me.
In my case on OS X 10.8 and PyCharm 3, IDE was automatically picking different installations of Python. I noticed this in Eclipse Pydev, which picked up the one right one and worked as expected. It was not easy to notice the difference between the two:
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/python
I follow the instructions under this question:
How to install OpenCV on Windows and enable it for PyCharm without using the package manager
After that it does not work and I reinstall the pycharm ide without any other changes and now it is working perfectly.
I know that this is not the best answer, but after a lot of time wasted and trying different workarounds this was the one that solve my problem, I hope it can help you.
After two days test,I finally fix this issue:
The difference:
Uninstall python 3.7.2,install python 3.7.7.
Change the path where python install.(I strongly doubt that the cause is that my PATH of opencv-python has some Chinese characters.It should have only English).
Then do:
Install the opencv-contrib-python.
I hate to give a "works for me" answer, but maybe the details on my environment will help you identify the problem on your end.
I've never used PyCharm before, but I just did a test on Mac 10.6.6 using PyCharm 1.1.1, with Macports opencv +python26. The autocomplete worked fine for me the first time. I also closed and re-ran PyCharm and was able to autocomplete without doing anything further. I also had no issue with autocomplete for other native extensions I tried like cjson, procname.
.
Perhaps it is a platform-specific issue (Windows?), or a bug affecting an older version of PyCharm?
In my case, include opencv in the path install-opencv-4-on-windows. and add it to the project settings, if none of this works for you, I recommend that you install anaconda change the python interpreter and use the anaconda interpreter.
for this go to : file -> settings -> project:test -> python interpreter and select conda interpreter
if you dont have anaconda you can download at https://www.anaconda.com/
follow the steps in the link python-opencv to install opencv in anaconda

Package not found in python, despite loading jupyter notebook from environment w/package

I have a fresh installation of Anaconda on OS X, and I'm following the instructions on this page to the letter, in order to create the appropriate environment.
When I enter conda list after activating the environment, pandas and matplotlib are both listed.
But when I open the provided jupyter notebook, or when I create a new jupyter notebook and type import pandas as pd, I get a 'there is no module called pandas' error. Ditto for matplotlib.
Happy to provide any more information that would be helpful in figuring out the problem. I feel like I run into problems like this a lot, so general strategies for debugging this kind of thing are welcome. Thanks!
EDIT: OK, I've fixed the problem for now, but I still feel like I'm missing something.
The problem was that there was no jupyter/ipython notebook kernel for the version of python in this env. So when I launch the notebook, even within the env, the correct version of python doesn't load, and some packages aren't available.
The solution is to add the kernel as described here: Using both Python 2.x and Python 3.x in IPython Notebook
It seems a bit odd to have to install a different ipython-kernel for every environment, but maybe it's not. I guess I just thought the correct version of python would load in the notebook as long as the notebook was launched from the env.
Does anyone have a better solution?
Since both your Py2 and Py3 kernels need different, version specific sets of packages to support them, the best and most convenient solution seems to be the one it sounds like you followed -- use anaconda, install either version as your default, then install an env with the other. If you want pandas available to both versions, you will need to make sure you conda install it in both the root and the other env. Jupyter is a bit magical in that it can be launched from either environment, yet will recognize that an ipython kernel exists in a different env and make both available to you.
It sounds like this may have worked against you slightly, though, and that you either launched jupyter from an env that didn't have ipython installed, but did have pandas. Jupyter found the ipython kernel in the other env, but you didn't have pandas installed there yet. At lest thats a theory. Solution remains to install pandas and ipython in both. Doing conda install anaconda in both envs will give you lots of packages, if space isn't a concern and may save you some of this aggrivation.

Categories