Force eclipse to reload Python modules - python

I have started a Eclipse PyDev project, and found out that BeautifulSoup was missing.
I installed it using easy_install, and now the scripts runs fine from the command line. Eclipse, however, still thinks that BeautifulSoup isn't installed, displaying an annoying error message and not supplying any introspection or auto complete.
How can I force Eclipse to reload the system's python package list?

You have to reconfigure the python interpreters. Normally the automatic configuration utility should discover everything by itself, but otherwise you can manually add/remove packages. Here's a screenshot of where the settings are located:
In the only occasion in which I can recall I needed to do that, all I did was to remove the python interpreter from the list and running the Auto Config procedure again, but it should also be possible to simply add a library (bottom half of the screenshot).
HTH!

Related

Adding Python 2.7 & 3.x Interpreters to PyCharm

I'm having issues adding a project interpreter to PyCharm from a new Anaconda environment. I have Anaconda2 installed with one Python 2.7 environment (C:\Anaconda2\python.exe) that I've been using on Pycharm without issue for several months.
I am attempting to add a second Python 3.6 interpreter (from C:\Anaconda2\envs\py36\python.exe) to my PyCharm. After adding the Local Interpreter to Pycharm, I run into a MS Visual C++ Runtime Error R6034 "An application has made an attempt to load the C runtime library incorrectly".
From cursory googling, it seems that there could be a runtime DLL conflict (potentially msvcr90.dll) between Python 2 & 3. All fixes I see involve editing the executable path of the application, but I don't think this is feasible for my Pycharm use case. How do I get rid of this error, or just generally be able to use both Python 2 & 3 interpreters through my PyCharm?
I think that's the problem with Anaconda and different msvc dll in the computer.
You can test the conda command in the command line, to see if R6034 happens. If it happens, try the following solution:
I had a similar problem with Anaconda3 and Python27. I solved this problem via executing the following command in cmd, outside of any conda environment:
conda install msvc_runtime
After installing the packages, open a new command and test if the R6034 error still appears.
I had a similar issue and was able to resolve it by selecting:
File --> Invalid Caches / Restart...
from PyCharm's main menu.
You may also want to double check that any Conda Environments that you have defined as Python Interpreters in PyCharm are properly configured per the docs
This issue was absolutely maddening. Million R6034 error windows would just keep popping up one after another if I just wanted to get help on a function. I researched it for months, on/off, opened tickets with JetBrains to no avail.
If you need to have multiple versions of Anaconda, and if you have Anaconda paths in your PATH, before launching PyCharm, delete all Anaconda paths from PATH, and then start PyCharm. You need to create a separate wrapper launcher script for PyCharm to fix PATH before PyCharm is started. Note that alternative of starting PyCharm and then fixing interpreter and python console PATHS inside PyCharm do not really work. Because PyCharm may be using a system path to access python to read documentation etc. So the only clean fix is to fix the system PATH before PyCharm starts.
Once you understand what needs to be done, then you can use your own steps/tools. This worked for me:
Create a script that modifies PATH. I used Python for that, sed or any other tools are fine too. The script simply examines each path element and removes it if it refers to Anaconda, and then puts it back together:
path_cleanup.py:
path_old = os.environ['PATH']
path_python_removed = [loc for loc in path_old.split(pathsep) if not ('python' in loc or 'Ana' in loc)]
print(pathsep.join(path_python_removed))
Create Powershell script to fix PATH and start PyCharm from that clean environment. To find PyCharm path, the simplest is to start it up the usual way, and head to Task Manager, right mouse click on pycharm64.exe process and select "open file location" to get the full path.
pycharm_clean.ps1
$Env:Path=python path_cleanup.py # call the script to fix the PATH
start-process $PYCHARM_PATH\pcharm64.exe -WindowStyle Hidden # enter your full path to pycharm and put it into background.
You can create a shortcut to launch pycharm_clean.ps1 + you can add it to your windows start up folder to be launched upon login: %APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup\
If you use BASH inside Cygwin, then steps for path clean up require a bit more tuning, but nothing you cannot do. If you need help, put a comment and I can add that script as well.

New python interpreter opens upon importing a package (control)

This is my first post so be gentle! I'm also in the process of learning python independently (trying to make engineering-related webapps using flask).
I have set up a project using virtualenv, and I've used the virtualenv-associated pip (what do I call this?) to install control.
Now, when trying to play around with the control package to play around with it, I am running an instance of the virtualenv's python3 interpreter (I've tried doing this by using the python3 command with the virtualenv activated, and by executing the project's proj/bin/python3 command) and I import control.
Oddly, this opens another python interpreter running on my desktop. Here's the
icon that appears on the mac doc.
Why is this second interpreter opening upon importing the control module?
Thanks for any help!

PyCharm 5.0.1 doesn't resolve builtin modules / methods

My PyCharm 5.0.1 installation does not resolve references to any builtin modules or methods:
As you can see, I have installed python over cygwin.
I already tried:
reinstalling / updating the python installation (from 2.7.9 to 2.7.10)
reinstalling pycharm
adding a interpreter path to the python-skeletons in the pycharm installation directory (this was immediately removed by the ide when saving the settings, implying, that it already is embedded)
removing the interpreter (this removes the warnings, but also the code completion, and import asdflkjasd is valid as well)
adding various paths like /lib/python2.7/site-packages/ to the interpreter packages option
None of these improved the situation.
How can I fix this without installation outside of cygwin alltogether?
This is an update with a much better solution than my previous answer (which I completely missed that OP was asking for a solution that didn't require exactly what I suggested).
Like Carl commented above, updating python-skeletons is actually the way to go, however, if you're using Cygwin, the interpreter paths are a little wonky, and PyCharm won't always automatically add the right paths. For me, PyCharm handled it just fine in version 4.5.4, but not 5.0.4.
You'll find the python builtins in your Pycharm config directory, probably at:
C:\Users\[USERNAME]\.PyCharm50\system\python_stubs\-[RANDOM_STRING_OF_NUMBERS]
Just manually add this path (or paths) to your interpreter and it should resolve your problem. You can do the same for your site-packages folder if that's currently polluting your project structure space.
To get to the right menu:
Click File -> Settings
Navigate to Project -> Project Interpreter
Click the gear on the top right and click "More"
Select your interpreter and click the "Show paths" button on the right
Instead of clicking refresh, as many other posts suggest, click the "Add" button on the right and add your paths
There's a handy screenshot uploaded by r---------k on the updating python-skeletons post that if that helps you.
Try installing the Python package for Windows from
http://www.python.org/download/windows and point PyCharm to that
interpreter instead.
Settings -> Project -> Project Interpreter -> Gear -> Add Local
You may also need to install PyCharm's Python packaging tools (you
should see a link on the bottom of the Project Interpreter page if it
isn't installed already).
While this may not be a perfect solution depending on your workflow
because PyCharm will no longer be using Cygwin's python interpreter,
but this at least got rid of those pesky squiggly red underlines for
me.
I use Windows 10 x64, Python 3.5.1 and PyCharm Community Edition 2016.1.4
I have the same problem and sovled it by runnig PyCharm in admin mode (it is required only once).

PyDev Debugging

My interpreter is the python 2.6 interpreter that comes with cygwin.
I have a pydev project that contains a linked folder.
In the folder, due to outside constraints, I have two sub-folders, one with a bunch of scripts I develop, and one which serves as the run directory for all my run configurations.
When I run the project (not debug) everything works fine.
However, when I choose to debug the project, my custom modules aren't found, and the import fails.
I tried adding my scripts folder to PYTHONPATH, but that didn't help, and when I printed sys.path It contained weird stuff, all of the form:
<path to run directory>/<path to entry in PYTHONPATH>
I can't make heads or tails out of it.
I'll appreciate any help.
Unfortunately, that's a known issue. PyDev does not support Cygwin for debugging. The primary reason is that the paths that Python reports don't match the paths you configure in windows, so, a translation step would be needed for each path (even some other areas such as code-completion or code-analysis could have problems).
You can probably do this translation yourself at eclipse/plugins/org.python.pydev_x.x.x/pysrc/pydevd_file_utils.py (instructions on the file), but note that this may be more work than it's worth (the recommended approach is using a native Python install on Windows instead of through cygwin) -- or if you need an interpreter on Linux, develop on Linux :)
Thanks, you made my day, its actually very easy,
you have to change the PATHS_FROM_ECLIPSE_TO_PYTHON variable inside pydevd_file_utils.py as,
PATHS_FROM_ECLIPSE_TO_PYTHON = [
(r'C:\Users\usernam\workspace-cpp\python-proj\src',
r'/cygdrive/c/Users/usernam/workspace-cpp/python-proj/src')
]
But this needs to be changed for all your own python source files you desire to debug
I am happy to announce a new release of ePyUnit, which solves the load-path issue of 'pydevd.py'. This works from within Eclipse/PyDev as well as from an arbitrary process started from the command line.
ePyUnit now includes the automation of remote debugging with PyDev and Eclipse by 'pydevd.py'. This works seamlessly for the 'subprocess' call as well as independently started command line processes.
See:
https://pypi.python.org/pypi/epyunit
https://pythonhosted.org/epyunit/
For basics of remote debugging:
http://www.pydev.org/manual_adv_remote_debugger.html
Also enhanced unittest integration into PyUnit.
Comments and fixes are welcome.
Have fun...

How to debug SCons scripts using eclipse and pydev?

I'm a newbie to SCons and also using pydev. Can someone help me with instructions on how to debug scons scripts using Eclipse and pydev? Is it even possible considering the fact that SCons is a seperate app and not an extension to python?
You are right. Since the SCons is python based, the SCons scripts are debuggable via EClipse PyDev. For this, you need to do the following in the debug configuration...
1. Under the main tab, set the main module to the SCons file which will be available under the python/scripts directory if you have installed SCons. If you have not run the install of SCons you can point to this file under the SCons directory.
2. Under the arguments tab, set the working directory to the root of your project.
Now set the breakpoint either on SConstruct or SConcript and run in debug mode. That's all!!
With this approach you can not only debug your product code but also the build scripts that builds your product :-) Happy Debugging!!!!
I'm not an Eclipse expert, but since you didn't get any other answer...
If you make the SCons source a part of the Eclipse project, and run the whole command from within Eclipse it should work like any Eclipse debugging. SCons is written in Python, there is no reason it shouldn't be debuggable in Eclipse just like anything else.
if you are using SCons for C/C++ development and Eclipse CDT check out http://sconsolidator.com (within the next weeks), we will release our SCons Eclipse plug-in for free public use shortly. It also contains an "interactive mode" that allows SCons builds to run more quickly (no startup time) and also to debug SCons in a console. However, the tip with using PyDev still applies (can be installed alongside with CDT in the same Eclipse instance.
On MAC to debug scons through pydev follow Lennart's answer but with one simply addition.
Using Finder (or terminal) browse to where scons is installed. You can find this with the "which" command.
e.g. which scons
-> /usr/local/bin/scons
Make a copy of the scons file and call it scons.py.
Now when you create the Debug Configuration in Eclipse use scons.py as the "Main Module".
PS: To add a scons project to Eclipse I found it easier to use a "Linked Folder" pointing at /usr/local/bin/. i.e. Because I was getting a read-only error when trying to add the directory itself.
I've since gain more experience with SCons / Python and I'd recommend using python's pdb module. To use it simply add the following code to your SCons/Python files.
import pdb; pdb.set_trace()
When the file is run from the command line a breakpoint will be hit at this line. I also moved away from Eclipse. A lightweight editor will be just as good for Python development. I use Sublime.
As an addendum: on Windows, I had to copy the scons-installed files to reside under C:\Python27\Lib\site-packages\scons in order for this to work. Adding the original installed location, qualified with the version number, to the PYTHONPATH, did not work.

Categories

Resources