Import error when using a python script that do not occur in ipython - ipython

All my install for python were working pretty well since soon. Now, I have a weird issue that generates import errors for some of my Python scripts and when using Ipython those import performs as expected.
This issue does not depend on the working dir (tested this several times with the same result). And I didn't change anything in my .bashrc regarding PYTHONPATHs.
So this might be a noob question, but is there an option in Ipython to display everything Ipython is doing when I run a command, so that I can track which is the package Ipython succesfully imported?
The packages I have trouble with are actually yaml, matplotlib cloud Image. Is it possible that an update from 2.6 to 2.7 is responsible for that? (I work on OSX Lion and most of the packages are installed via macports and updated using the upgrade outdated command).
As I think I can probably fix this myself with the command I asked for, don't bother seeking further for package compatibility or anything if you got the Ipython command that might suits me.

The difference of imports between python and ipython resulted from a cross defined python reference library (when installing most of the python libraries with macports and some without any known ports with other package managers).
Reinstalling the whole python libraries using the process described in http://astrofrog.github.io/macports-python/
corrects the issue and it is preferable to install manually the libraries that don't have any known ports (for instance with a setup build/install process).

Related

I'm on VSC and I had to change the python version using the different environments, now when I import modules VSC says they aren't installed

I needed to change to a different python version because one of my imports had randint in it from random and my lanky python 3.8.10 doesn't like it.
I'm installing my modules for my discord bot as I would usually do, but now it hits me with
Import "discord" could not be resolved
(same for all other modules I've tried importing)
...
Using pip freeze I can see it's there, it's installed, but VSC refuses to recognise it.
I've tried going back to my original 3.8.10, and it works perfectly, it just means I need to remove the faulty import and then my code won't work.
I've tried using all the other interpreters but still, nothing happens. Only on 3.8.10
Any help?

simpleitk installation in anaconda

i installed simpleitk in anaconda using command
conda install -c simpleitk simpleitk then followed link https://github.com/SimpleITK/SimpleITKCondaRecipe to build it but it's not connecting to itk.org to build.
import SimpleITK as sitk on jupyter notebook is working but sitk.show() is not working. moreover when i tried to follow the commands from http://insightsoftwareconsortium.github.io/SimpleITK-Notebooks/Python_html/00_Setup.html,
from downloaddata import fetch_data, fetch_data_all not working.
even the command fetch_data_all(os.path.join('..','Data'), os.path.join('..','Data','manifest.json')) is not working. i am very new to simpleitk and don't know whether it is due to build not processed. please tell me how to solve my problems. i have been trying from many days, pl help me. moreover how to make imagej as default for simpleitk. i know lots of questions but i would be greatful if solved.
You seem to be having multiple problems, all of which have to do with installing a working environment and less specific to SimpleITK.
You installed SimpleITK using the conda install command, so there was no need to build it using the conda build command. Check that you have it installed correctly and see which version you have:
import SimpleITK as sitk
print(sitk.Version())
The functions fetch_data and fetch_data_all are part of a module found in the SimpleITK notebooks repository. To use the code from that repository you will need to clone it using git:
git clone https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks.git
Then you can run the notebooks or copy the relevant modules to your directory and work with them there.
The sitk.Show() command assumes that you have the ImageJ/Fiji program installed which is likely why it is not working (I am guessing here as you did not provide sufficient detail).

Elpy to allow pyenv to work on a project basis

I've used Emacs for all my coding projects so far. Soon I will start some python projects for the first time and would love to stick to Emacs for these as well.
I was looking into elpy which seems to provide already alot of desired functionality. The part I was not able to figure out completely is the following. I like to define virtual environments and python version to be used on a project basis. Let's say I start a project A, then I would use pyenv-virtualenv or pyenv-virtualenvwrapper to set it up
pyenv virtualenv 3.4.2 my-virtual-env-3.4.2
by doing this I've linked the python version 3.4.2 to that specific virtualenv / project. I have two questions regarding this in combination with elpy.
Question: This is a rather basic one. All the above can be achieved via the terminal. What is the advantage to emacs to support this? The workflow for me would be: Create project with associated virtualenv and python version. Activate virtualenv and start coding in emacs. If I need to install a package I will run pip in the terminal to ensure virtualenv is captured properly. There must be a reason why it's beneficial to support this in emacs. With my lack of knowledge I just don't see it :)
As pointed out there is for sure a good reason why we want emacs / elpy to support this. My second question would then be
**Question: How can I achieve this in emacs? Lokks like this blog has a solution. I was wondeirng if someone already tried this setup if it is a neat solution with makes sense conceptually. **
Well I strongly guess the goal is to use more features than just syntax highlighting: flycheck/flake8/linting, refactoring, elpy's test runner to use the right python version, install a pip package directly from emacs, stuff like this. You can carry on doing this in the terminal, but once you want an emacs feature, you'll need to set it up.
IĀ found two modes to do that (see wikemacs python page and doubled-checked on melpa): pyenv-mode (in melpa) and pyenv-mode-auto (change the version when there is a .python-version file).

Install Ipython notebook without Internet connection

I followed these instructions:
http://ipython.org/install.html
Used last way to install (downloading source and "python setup.py install").
After that, console ipython worked fine, but trying to run notebook gave me error.
I always searched errors in Google and it always was a missing package.
Notebook probably depends on external packages.
After manually installing 2 packages it still gave me error.
Gave up and uninstalled everything (including Python itself).
Is there any way to manually download and install the notebook?
Do you know of any finite number of files/packages I have to download and install so the notebook will run just fine?
Thank you.
As you are using Windows, I suggest you to install Winpython.
It includes all the libraries and tools (e.g. IPython) you will need in the same executable. So you only need to download the desired version and then you can pass that version using a USB stick to the computer without internet.

IPython notebook kernel dies on import

I am running IPython Notebook on Enthought's Canopy 64 bit distribution, Ubuntu 14.04.
I've tried install libtiff, but when I import it in IPython Notebook, the kernel always dies at the import statement. What could possibly be causing this? Canopy is my default Python distribution, my paths all seem like they're set up appropriately, although I'm convinced that something in my Python setup is borked.
Any advice is appreciated.
EDIT: I'll be more specific. Output of sys.path:
['',
'/home/joe/Enthought/Canopy_64bit/User/src/svn',
'/home/joe/Canopy/appdata/canopy-1.4.1.1975.rh5-x86_64/lib/python27.zip',
'/home/joe/Canopy/appdata/canopy-1.4.1.1975.rh5-x86_64/lib/python2.7',
'/home/joe/Canopy/appdata/canopy-1.4.1.1975.rh5-x86_64/lib/python2.7/plat-linux2',
'/home/joe/Canopy/appdata/canopy-1.4.1.1975.rh5-x86_64/lib/python2.7/lib-tk',
'/home/joe/Canopy/appdata/canopy-1.4.1.1975.rh5-x86_64/lib/python2.7/lib-old',
'/home/joe/Canopy/appdata/canopy-1.4.1.1975.rh5-x86_64/lib/python2.7/lib-dynload',
'/home/joe/Enthought/Canopy_64bit/User/lib/python2.7/site-packages',
'/home/joe/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/PIL',
'/home/joe/opencv-2.4.9',
'/home/joe/Canopy/appdata/canopy-1.4.1.1975.rh5-x86_64/lib/python2.7/site-packages',
'/home/joe/Canopy/appdata/canopy-1.4.1.1975.rh5-x86_64/lib/python2.7/site-packages/IPython/extensions']
As for how to install Python packages, I assume I go to ~/Enthought/Canopy_64bit/User/lib/python2.7/site-packages and run pip, setup.py, or a shell script, per the specific package's instructions. Is that correct? The article that I linked has the following line: "To install a package which is not available in the Canopy / EPD repository, follow standard Python installation procedures from the OS command line.", which seems to imply that I install per package instructions.
In .bashrc, I have the following:
VIRTUAL_ENV_DISABLE_PROMPT=1 source /home/joe/Enthought/Canopy_64bit/User/bin/activate
export PYTHONHOME=/home/joe/Enthought/Canopy_64bit/User/bin
export PATH=/home/joe/Enthought/Canopy_64bit/User/bin
export PYTHONPATH=/home/joe/Enthought/Canopy_64bit/User/bin
From what I understand of the linked articles, this means I'm setting Canopy User as my default Python distribution. I'm sure I'm doing something a bit over my head here, but I can't understand what else I need to do to fix this issue.
Worse yet, now I'm getting an "ImportError: No module named site" with these .bashrc settings, when trying to start IPython notebook or python from the command line. I can run only from the Canopy GUI.
Closing this. I made it harder than necessary.
It turns out, the PYTHONHOME and PYTHONPATH .bashrc variables were causing some conflicts. Commenting them out seems to have resolved the issue.
Installing outside packages does, indeed, happen from the home (~) directory.