Error to launch IPython shell after source install - python

I have an account in a CentOS server without sudo permission. As a result, I tried to install IPython from source code by python setup.py prefix=<my home directory>.
However, I got the Error:
Traceback (most recent call last):
File "/usr/bin/ipython", line 19, in <module>
from IPython.frontend.terminal.ipapp import launch_new_instance
ImportError: No module named IPython.frontend.terminal.ipapp
I found a question same to mine: IPython import failure and python sys.path in general.
I followed the asker's instruction to add the directory of my IPython to the IPython execution file.
#!/usr/bin/python
"""Terminal-based IPython entry point.
"""
import sys
sys.path.append("./Ipython directory")
from IPython.frontend.terminal.ipapp import launch_new_instance
launch_new_instance()
However, I got the same error as well. So I want to know how can I launch IPython correctly? Thanks.

You probably want to install with the --user flag, which should put it on sys.path automatically.
python setup.py install --user
If you need to use --prefix for some other reason, then make sure that the directory you add to sys.path is the folder containing the IPython package, not the IPython directory. It will probably end with 'site-packages'.

I copied the IPython source folder into ~/bin/. The execution file of IPython can recognize the module in IPython and the IPython shell launches successfully.

Related

VS Code is not recognizing 'nmap'

I am trying to make a nmap scanner for the InfoSec Certification on freeCodeCamp.org and cannot get Visual Studio Code to recognize that I have installed nmap. I am very beginner and in the process of learning.
from cProfile import run
import nmap
scanner = nmap.PortScanner()
print("Welcome, this is a simple automattion tool")
print("<------------------------------------------->")
When I run this in VS Code I get the following in the terminal:
PS C:\Users\mjame\OneDrive\Documents\Jim\Coding\fcc_python_for-pen_testing\nmap_scanner_1> python3 scanner.py
Traceback (most recent call last):
File "C:\Users\mjame\OneDrive\Documents\Jim\Coding\fcc_python_for-pen_testing\nmap_scanner_1\scanner.py", line 2, in <module>
import nmap
ModuleNotFoundError: No module named 'nmap'
PS C:\Users\mjame\OneDrive\Documents\Jim\Coding\fcc_python_for-pen_testing\nmap_scanner_1>
I have so far:
Updated to the current Python 3.10.7
Installed Nmap the first time from https://nmap.org/ for Windows
Uninstalled Nmap
Reinsalled Nmap using >>>pip3 install python-nmap
For future searchers (as in my comment above), if you installed a module with pip3 but are still getting module import errors, try python3 -m pip install <module-name>.
Not sure how/why this happens (pip3 installing somewhere that python3 is not looking for modules - maybe PYTHONPATH-related), but the above can [usually] help.
It seems that Python cannot find nmap module.
You can either add it to path in Windows via Start -> Edit system environment variables -> Environment variables... and then edit PATH VARIABLE by adding at the end path to nmap module that you have installed or move the module to default Python modules directory which should be C:\Users\YourLogin\AppData\Local\Programs\Python\Python310\Lib\site-packages

ImportError when importing in python notebook, but import works fine in terminal?

The import works when I call it from the command line, but when I call the import in the ipynb I get the following error:
ImportError: libmkl_intel_lp64.so: cannot open shared object file: No such file or directory
I have already added the path to libmkl_intel_lp64.so to my bashrc file, so I am not sure what else I can do to fix this import error in the notebook.
Your command line python interpreter,
and your jupyter notebook kernel,
have different environments.
Use one of these techniques to help you debug the path problem:
$ python -m site (from bash prompt)
import sys; from pprint import pp; pp(sys.path) (within a cell)
Do yourself a favor, and use conda to manage your environment.
https://docs.conda.io/en/latest/miniconda.html
Be sure to conda activate myfavoriteenvironment
before you start the jupyter kernel.

How to run the python webapp using flask & anaconda from vscode?

I have installed Anaconda-Package, Flask, Pip & Vscode. I am currently running the development project on localhost using "pipenv shell" command then "flask run" command in vscode.
It works well on http://127.0.0.1:5000/ for simple webapp. But I want to display the prediction charts & tables on a webpage using pandas, numpy etc.
So, When I try to import
import pandas as pd
import numpy as np
It displays this ->
flask.cli.NoAppException
flask.cli.NoAppException: While importing "app", an ImportError was raised:
Traceback (most recent call last):
File "c:\users\mdev\.virtualenvs\flask_md_project-itylmdvv\lib\site-packages\flask\cli.py", line 240, in locate_app
__import__(module_name)
File "D:\flask_md_project\app.py", line 4, in <module>
import numpy as np
ModuleNotFoundError: No module named 'numpy'
above error as image
How do I use pandas,numpy,matplotlib etc from anaconda package along with flask through vscode for my python webapp ? Please help 🙏
According to the information you provided, the modules "pandas" and "numpy" are not installed in the Python environment you are currently using.
When we use the conda environment in VS Code, we use it as a python environment. Therefore, in this environment we need to install the module and then use this module. Usually, the module storage location of conda environment is (for example, base conda environment): "\users\username\anaconda3\lib\site-packages".
We can use the command "pip show pandas" in the VS Code terminal to check the installation location of the module:
For more information about flask in VS Code, you could refer to: Flask Tutorial in Visual Studio Code.
Install numpy on anaconda by running;
conda install numpy

Getting an error for a module that I definitely imported

import pyinputplus as pyip
while True:
prompt='Want to know how to keep an idiot busy for hours?\n'
response=pyip.inputYesNo(prompt)
if response=='no':
break
print('Thank you. Have a nice day.')
When I run my above code , I get this error:
Traceback (most recent call last):
File "c:\users\XXXXXX\mu_code\idiot.py", line 1, in <module>
import pyinputplus as pyip
File "c:\users\XXXXXX\mu_code\pyinputplus\__init__.py", line 15, in <module>
import pysimplevalidate as pysv # type: ignore
ModuleNotFoundError: No module named 'pysimplevalidate'
I cannot figure it out. The module is definitely installed. I've even moved it from the folder it was originally installed in to the mu folder where the py file is saved. Any help would be appreciated.
The ModuleError says that you do not have pysimplevalidate installed.
Using the same python executable as you are using to run your script (idiot.py), run
python -m pip install pysimplevalidate
or, even more bullet-proof:
<path_to_python.exe> -m pip install pysimplevalidate
If you are not sure what python executable the script is using, you can check it with
# put this on top of your script
import sys
print(sys.executable) # will print C:\path\to\python.exe

How to get numpy working properly in Anaconda Python 3.7.6

I am trying to use NumPy in Python. I have just installed Anaconda Python 3.7, and that all seemed to go smoothly. However, I cannot import numpy(using the line import numpy). When I do, I get the following error:
C:\Users\jsmith\anaconda3\lib\site-packages\numpy\__init__.py:140: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
from . import _distributor_init
Traceback (most recent call last):
File "C:\Users\jsmith\anaconda3\lib\site-packages\numpy\core\__init__.py", line 24, in <module>
from . import multiarray
File "C:\Users\jsmith\anaconda3\lib\site-packages\numpy\core\multiarray.py", line 14, in <module>
from . import overrides
File "C:\Users\jsmith\anaconda3\lib\site-packages\numpy\core\overrides.py", line 7, in <module>
from numpy.core._multiarray_umath import (
ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\jsmith\anaconda3\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import core
File "C:\Users\jsmith\anaconda3\lib\site-packages\numpy\core\__init__.py", line 54, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
1. Check that you expected to use Python3.7 from "C:\Users\jsmith\anaconda3\python.exe",
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy version "1.18.1" you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.
Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.
Original error was:
DLL load failed: The specified module could not be found.
I can see it in the Enviorments tab of Anaconda Navigator, and when I try to use it in Eclipse(Pydev) it shows up under forced builtins. I took a look at my PYTHONPATH, and both my enviorment in Eclipse and my base python directory (jsmith/anaconda3) are in it. I have tried importing other libraries I see under forced builtins,and those work fine, yet numpy seems to be the only one with issues. Calling pip install numpy tells me it is already installed with version 1.18.1. I looked at this stack overflow page, and ran the first command in the answer(conda create -n test numpy python=3.7 --no-default-packages) in anaconda prompt. This worked, and then I realized the test was specific to the question, and tried base instead, and got this error:
CondaValueError: The target prefix is the base prefix. Aborting.
However calling conda activate base did nothing.
As mentioned in the comments by #cel uninstalling and reinstalling numpy using pip uninstall numpy and pip install numpy made it work.
I better way is to
import os
import sys
os.path.dirname(sys.executable)
This will give you the path to your environment. Put the path into the settings for python
Open the Anaconda Prompt:
Then, you have to go to the Conda Environment that you want to use in PowerBI. Am having an environment 'temp', so I activate it first in the 'Anaconda Prompt':
(base) C:\Users\ashish>conda activate temp
Then I go to the directory having the "PowerBI" executable file in the installation folder:
(temp) C:\Users\ashish>cd "C:\Program Files\Microsoft Power BI Desktop\bin"
Then, I launch PowerBI from the Prompt:
(temp) C:\Program Files\Microsoft Power BI Desktop\bin>PBIDesktop.exe
This fixes the NumPy error you are getting. If you want any other package to use with PowerBI, install that package in the respective "Conda Environment" (in my case it is "temp").
Make sure the Python home directory (Anaconda3) has been added to the 'Power BI Desktop' global options in the Python scripting section too.

Categories

Resources