add python3 library to python3.6 path - python-3.x

hello I'm new to python3 and python3.6, I usually use pip3 install to add old libraries to my python3 path.
I recently picked up python3.6 for managing my home servers with its asyncio functionalities however my python3.6 interpreter is unable to locate pwnlibs and am thus unable to reuse my old code.
I tried:
import sys
import os
sys.path.append(os.path.abspath(pwn.__file__))
import pwn
debugging results:
on python3.4 os.path.abspath(pwn.__file__) returns the correct path to the library

While sys.path.append is a valid means to add to your python path at runtime, you can't get the path from a module you have not yet loaded.
Instead you should install your packages using pip3 or in a specific location and add that to your path either at runtime or via the PYTHONPATH environment variable.
I would guess since you mentioned pip3 already however that you had the pwn package already installed when you tried with 3.4 and your install of Python 3.6 is not using the same paths as your Python 3.4 install. Try comparing your python paths from 3.4 with 3.6 by comparing the output from sys.path.
Lastly, just as a note, if you are using the pwntools package, it doesn't yet support Python 3, so if you are simply copying the folder, be aware it might not function correctly or at all.

Related

XGBoost module not found in site-packages. Imports but doesn't work. (mac OS)

I was able to install xgboost on my mac and have it so that I can import the module without any errors. However I cannot use it. When I try to import XGBRegressor. I get the following error :
cannot import name 'XGBRegressor' from 'xgboost' (unknown location).
Some of the support for this type of problem says that there may be more than one xgboost location, and that python is selecting the incorrect xgboost, however I have not been able to find how to fix this problem.
When I print the xgboost.__file__ location, it returns 'None'. However I know its in the site-packages folder in my python path.
I have python 3.9
Maybe this.
conda install -c conda-forge xgboost=0.6a2
Then, restart Spyder and re-run!

Pandas install or import in IBM SPSS Statistics Version 26

I have installed the latest version of IBM SPSS Statistics(Version 26) which has pre installed python 3.4 and 2.7. i am trying to use version 3.4 python. i am able to import modules like pip , sys , os etc. i tried pandas the same way. i am unable to do so. getting error no module found. Hence going through our forum and IBM support did the following changes.
received the following error
1) tried pointing the site-packages via
import sys
# Assuming windows and standard python folder here.
sys.path.append(r"D:\Python34\Lib\site-packages")
2) changed the path in the settings of SPSS
3) Tried installing pip in the below folder as suggested in the forum but got message i have already installed the updated version.
C:\Program Files\IBM\SPSS\Statistics\Subscription\Python3
4) following versions of python were installed
have tried what i could. Need your expertise help to fix the same which will help me to install/use modules needed for SPSS. Thanks.
This is going to be painful to explain, I'll do my best.
As far as I can tell, you're on windows. Usually when we need a new package, we just open cmd and type pip install xxx (assume you added python to path when installing it). The reason that this works, is because when you type pip install xxx in cmd, windows recognize pip to be a command because python path is in system variables. Windows know that I can execute pip install with this python path.
However for SPSS python (3.4), that python had a different path in the system. Thus when you only have the 3.7 or 3.8 python in path, windows cannot install package to you 3.4 python, and I'm not sure if you can have more than one python path in system.
In order to fix this, you need to first figure out what's the path to your 3.4 python, then in this page you can follow the instruction to remove your 3.7 or 3.8 python in path, and add your 3.4 path, then you can do pip install xxxx for whatever package you want
I did the same thing with a arcgis python distribution, hope this works for you. If the attached page does not work, just google add python path to windows and look for a instruction that works on you PC
Oh and the reason that you can import pip, sys and some other package but not pandas, is because python is 'battery included', it comes with tons of packages pre-installed for additional functionality, but pandas is not one of them.
Fixed it since my ananconda had version 3.7 .i created virtual environment and installed 2.7 python with anaconda package. Pointed SPSS to the 2.7 folder and was able to import pandas.

Unable to import Libraries even though Installed in Anaconda on Pycharm

I am using Ubuntu 18.10(dual Boot win10), I have installed anaconda (conda version- 4.6.7) on ubuntu. After this Installation I installed Pycharm via snap on Command Prompt. Since Pycharm(version - 2018.3.5) didnt Detect my python Location automatically I set the python Interpreter via
Adding Location ->System Interpreter (As I didn't want any Venv) -> Path
But when I try to import opencv in Pycharm it says
ModuleNotFoundError: No module named 'cv2'
Python3.6 in Anaconda Bin is shown to which I have linked in Pycharm (I have also tried other Python files there as well but no luck)
When I run in Terminal: python3 -c 'import sys; print(sys.path)'
It shows:
['', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6
/lib-dynload', '/usr/local/lib/python3.6/dist-packages', '/usr/local
/lib/python3.6/dist-packages/setuptools-39.1.0-py3.6.egg', '/usr/lib`/python3
/dist-packages']
So could anyone help me out in this?? Thank You in Advance!!
Edit 1:
I am also unable to access any of the libraries from terminal Itself. So Could anyone help me with that as well. Should I export path of this Python in Anaconda bin folder to bashrc file in Ubuntu?
Edit 2:
The libraries affected is not just opencv. There are few other Libraries like Portaudio which are affected as well along with Opencv

How to solve ModuleNotFound Error in IDLE?

I am using ubuntu 18.04. I first installed Python along with anacondafrom terminal whose version is 3.7.0 and I have launched Jupyter notebook and Spyder as well. Then I installed IDLE whose version is 3.6.6+ and I am currently working in IDLE but then when I tried to import module,it shows the error: No module found. I checked for the path as well for both in IDLE and Terminal which are different.How do I solve this problem?
when I checked the python path,
In terminal,
/home/reema/anaconda3/lib/python37.zip:/home/reema/anaconda3/lib/python3.7:/home/reema/anaconda3/lib/python3.7/lib-dynload:/home/reema/anaconda3/lib/python3.7/site-packages
In IDLE,
['', '/home/reema', '/usr/bin', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages']
I tried appending in IDLE but it doesn't work.
Your problem is due to the different interpreters installing modules in different paths, and because the default interpreter at the command prompt is likely 3.7, while the installed Idle uses 3.6
The answer to your problem is to use pip to install new modules and invoke pip as follows
$ python3.x -m pip install ...
This way you know which interpreter is called, and each times the correct version of pip is invoked and, each time, the module is installed in the correct path for a given interpreter.
I have to add that, as far as I can tell, the Anaconda distribution does not support Idle.

cant find moduals even though sys.path searches in right place

I am working on widows10 with python3.7
I have downloaded opencv and numpy and sklearn(scikit-learn) and they are in C:\Python37\Lib\site-packages (where pip put them) and when I run
import sys
print(sys.path)
I get the output:
['', 'C:\\Python35\\Lib', 'C:\\Python35\\DLLs', 'C:\\Python35\\Lib\\site-packages', 'C:\\Users\\E6440', 'C:\\Python37\\python37.zip', 'C:\\Python37\\DLLs', 'C:\\Python37\\lib', 'C:\\Python37', 'C:\\Python37\\lib\\site-packages']
on cmd it says C:\Python37\Lib\site-packages which is one of the paths it looks in for when importing but then as soon as I run some code it gives a no module named ___ error
this is similar to the question python cant find module in sys.path but the comments in that one did not help me
edit
solved by using PYTHONPATH that was accurate to the python version
The package you're trying to import the module from may be available in the Python 3.5 installation too, but the package for Python 3.5 may be missing the module you're trying to import. Try moving the Python 3.7 paths ahead of the Python 3.5 paths in your PYTHONPATH environment variable.

Resources