Autocomplete Pycharm Pro 2017.1 - python

Dev. Box: Windows 7
Remote Box where project should be deployed: Redhat Linux
Project on remote machine does not utilise pip or virtualenv but rather an in house alternative to virtualenv.
I setup my remote interpreter in Pycharm via Ssh to the python interpreter in linux box and see all the modules on remote with version info listed.
Pycharm tries initially to upload Pycharm helpers to remote box but is I guess unable to install them as I imagine it cannot find usual python tools like pip, so I see a banner on the remote interpreter saying Setup tools not present on remote. Regardless when this preference window is closed pycharm initiates indexing I assume the remote interpreter and modules.
When I open a file in the code however after indexing completes I cannot get auto code complete to work for any module even standard library modules i.e. json, sys, os...
I tried to get more info on Pycharm Helpers that try to get installed but all I found was they get used for remote debugging and "scaffolding" which I can't find additional details as to what the latter means or if it is even relevant to get autocomplete to function.
Need help really badly on this, thanks in advance to anyone who can aide me in this matter.
Some collegues got around this by having Devbox be a Mac OS or any other linux distribution, cloning the project locally and then using the local interpreter option in Pycharm but unfortunately I can't utilise local interpreter even though the project is cloned because on windows Pycharm expects the local interpreter to be a .exe

Related

Importing python packages in Ubuntu server

I have a Ubuntu server with restricted access. There I will be hosting my application.
I trying to run Python scripts which were working with the default packages provided by the server. I want to work with numpy and other modules.
As I cannot install or download or do anything, I created a python server in my local machine (WINDOWS) using WSL to emulate the Linux file system and copied the python environment files to the application directory and deployed in cloud.
The problem is no matter in whatever way I try I cannot import numpy (or any module which I copied). I moved all the site-packages to the location of my Python script (As the current script's path will be there in the system path) and tried to import but no luck.
Please help me with crack this in any possible or impossible way.
I am trying to achieve this for the past 6 days and cannot do it.
Please, I have to achieve this at any cost. I have attached my latest structure.
Thank you in advance.
My Folder structure screenshot:
EDIT:
Ok. Let me get this straight. I have a Linux server (Ubuntu 18.04) where I am hosting an application. From that application, I am calling python scripts for some machine learning purposes. It is restricted server and I cannot access it. The only way that I found out the Linux distro version is through Java code by calling some terminal commands using "ProcessBuilder". As the server is highly restricted I cannot run any of the Linux commands like echo, set, export, sudo, wget/curl,...etc., Since, python3 is already provided by Linux (by default) I am using that python3 command to call my python scripts (from Java code using "ProcessBuilder") and execute them.
If it is a normal script (if I am using python standard libraries) it is working fine. In one of the scripts I am using "numpy". So, I want to import that module. I am doing the development in a windows environment. So, to emulate the Linux file system for importing packages I created a virtual environment in WSL with same Ubuntu version and installed numpy and then replaced all the symlinks inside those packages with the required files. Then I copied the entire environment and pasted in my resources directory (which is in windows environment) and deployed. No luck.
So, I made a zip file for only "site-packages" folder inside that environment. Then I copied the zip file and pasted in my resources folder and deployed. No luck. The error that I always see is "numpy.core._multiarray_umath". All the articles and in GitHub also tell us to re-install the package. But, I cannot install. I don't have any such access.
How can I import numpy without installation? If there is any work around to achieve this please explain, I will do it. Even if it is harder, complex and time-consuming I am okay with it. I want to achieve this.
Let me preface this with:
a warning to please check the AUP (acceptable use policy) of the server you are using, and/or contact the server administrator to make sure you are not violating any rules.
I can think of quite a few reasons why this won't work. If it doesn't, then there may still be workarounds, but they'll be technically complex.
So if I'm understanding you correctly:
You have very limited access to the server; basically only the ability to upload (apparently) and run Java code.
You've also been able to upload Python code and run it through your Java code through ProcessBuild.
You do not have access to log in to a shell, execute arbitrary command other than through ProcessBuild, etc.
Of course, you do not have the ability to install site-packages into the system Python environment.
So ultimately, what you'll probably need to do is something like:
Create a Python3 virtual environment (which doesn't seem to be what you are actually doing) on WSL. By a "Python3 virtual environment", I mean venv, which allows you to create a user-level (not system-level) directory with your packages.
So something like (from inside your project directory):
python3 -v venv venv
source ./venv/bin/activate
Your path will be adjusted so that your python3 and pip3 commands will be found in the venv path. pip3 install numpy will install it into this virtual environment (not the global/system Python).
Upload that entire venv directory to the server. You seem to have some way of doing this already.
You're going to have to have some way of running the Bash shell through ProcessBuilder. Since you have the ability to run python3 through ProcessBuilder, I'm kind of assuming that you will be able to do this as well.
You'll need to (through ProcessBuild) activate the virtual environment on the server, <path_to_project>/venv/bin/activate and, in the same Bash shell run your code.
This will look something like:
bash -c "source ./venv/bin/activate; python3 main.py"

Can I run the same Python code in Pycharm for mac & windows?

I have just started using python and pycharm, and I have a windows laptop and a mac where I need to work from. In specific, I created a project including a venv in my windows laptop which is uploaded in one drive and works perfectly for that laptop. So my question is; can I work on that same project from my mac?
Instinctively my answer would be no, because all the virtual environment files originally created in the windows venv are .exe which are incompatible with anything mac related. Trying to open the project and load the interpreter myself has confirmed that this doesn't work.
But then I stumbled on to this post, which would suggest that this person can run a project from a windows and linux OS with the only problem being that they only have to re-select the interpreter.
So is there any way that the above can be done, or a workaround at least? (e.g. creating two venvs for each OS or something).
Yes, you can run the same Python code on both Windows and Mac. You will need to create separate virtual environments on each because the Python interpreter is a .exe file on Windows and something else on Mac.
I suggest that you use git to track changes in your code. Then you can push your code to a service such as GitHub so that your changes are avaialble on all of your computers. You won't add the virtual environments to the git repository, though. These should be created separately on each machine where you want to work on your project.

Is it possible to have VS Code use a Python environment that's inside a VM?

I've set up a Django (2.1.1) development environment using Vagrant and I've installed the Python extension for VS Code. I'm getting an error from pylint saying it can't import django.db, which makes sense since all of the Python modules are installed in the VM, and VS Code is using the Python environment on the host.
Does anyone know how (or even if) you can connect VS Code to the environment running inside of the VM so that linting and intellisense work?
This depends on how the VM and host are connected. If the user has permission to the interpreter you should be able to create a custom Python Environment in Visual Studio that uses that interpreter and its modules for intellisense.
This will get it to work from visual studio but in your code you may need to specify where you are importing the modules from. See Importing files from different folder
Take a look at the extension Remote - SSH.
I opened my Vagrant virtual environment with configuration the command:
ssh -p 2222 vagrant#127.0.0.1 -i /Users/sb0y/vagrant/ubuntu/.vagrant/machines/default/docker/private_key
Works perfectly.

IntelliJ + Python plugin: Python remote interpreter gets created without classpath, does not work

When I create a new remote Python interpreter, IntelliJ doesn't find any dependencies to my code and doesn't seem to index any libraries. Most of the code is red. I think I've pinpointed that to the "classpath" being completely empty, which is unlike some other Python SDKs that I have added (local ones). Some of the times I am able to get it to populate the classpath with paths pointing to the IntelliJ Caches directory by clicking around in the interface, but I most of the times it does not work and I cannot reproduce how to make it work. How do I make sure the classpath gets populated correctly?
I am using IntelliJ Ultimate version 2016.2.1. with the Python plugin version 2016.2.162.43. I am developing on a Vagrant virtual machine and I'm adding a Python remote interpreter that is inside a virtual environment (venv) inside the virtual machine. When I add the remote interpreter, I use:
On the SDKs tab - the + button.
Python SDK
Add Remote
I select the Vagrant option
Point it to my Vagrant project directory.
Point it to the python3.5 executable inside my virtualenv
Add the SDK
Then the classpath looks like this: https://www.dropbox.com/s/3xbzopb4y9bhn0u/Screenshot%202016-08-11%2017.19.43.png?dl=0 and IntelliJ doesn't recognize any libraries/builtins. For other SDKs, the classpath contains several entries with remote_sources, python_stubs or python-skeletons in the name and they work.
As a workaround, I copied every entry from the local python interpreter classpath to the remote one and everything seems to work
Edit:
Actually, I don't know what triggered it, but some days after I wrote this, I noticed that IDEA started downloading source files from the server. I went to the interpreter settings, and the classpath entries I had manually added were gone and replaced by "system/remote_resources" entries. I think this is how it's supposed to work, but unfortunately I don't why I didn't work from the start nor how to trigger the correct behavior, it just started working on its own.
While this issue is a bit older, I had the same issue today with IntelliJ IDEA 2021.2.
I was able to solve this by using Navigate -> Search Everywhere -> Type interpreter -> Select Rescan Available Python Modules and Packages.
This prompted downloading of the remote resources and indexing. Afterwards, the classpaths were filled in properly.

Why won't PyCharm see my libraries?

If I do something like "import selenium" (or any other kind of third party library) in a .py file and then run it from the terminal, it works just fine. But if I make a new file in PyCharm CE and do the same thing, it can't find the library / module.
How can I fix this or get it to point in the right location? I use a Macbook Pro.
You need to setup your project in PyCharm to use the Python interpreter that has your libraries:
Go to: file->settings->project->project interpreter
And select the appropriate interpreter from the dropdown. After selecting an interpreter, the window displays a list of libraries installed on that interpreter; this should further help you make the right selection.
I've faced a similar issue on Pop!_OS after installing PyCharm via Flatpak. I think the installation is somehow incomplete, as I've had these issues (among others):
Installer could not create the menu shortcut due to the lack of credentials. Unlike during a typical installation, it wouldn't ask for the password and instead I had to uncheck that option altogether.
Built-in terminal defaulted to sh. Even after changing to bash, it would not read my .bashrc and many commands were missing.
After changing the interpreter into a local virtualenv, it would just default to Python 3.7 (even though the version was actually 3.8) and it didn't see any of my installed libraries.
When I've tried to use a Docker Compose environment, IDE failed to detect Docker Compose installation.
I've eventually uninstalled PyCharm and downloaded it directly from Jetbrains website to make it work correctly.

Categories