I'm trying to clone a repo to my machine to test changes for a pull request.
The repo in question is a clone of pytorch, and I want to add something to one of the files to fix an issue. I figured how to clone the repo, but I can't figure out how to import the pytorch libraries when I write a test file that contains something like:
import torch
x = torch.rand(5, 3)
print(x)
Where am I supposed to create a test.py file? How do I add pytorch (specifically my cloned version of pytorch) to the list of dependencies for Python to run with? I tried just creating a test.py file at the same level as the cloned repo, but i get the error message
"no module named torch.version". I am using VS code.
I'm new to using git and not extremely familiar with the structure of libraries like this. I tried looking through github, stack overflow and the pytorch docs but was unable to find an explanation.
Make sure your current selected interpreter doesn't contain pytorch, then before import torch, add the following code:
import sys
sys.path.append("\the folder that contains pytorch\")
Please have a try.
Related
I have connected a Github repository to my Databricks workspace, and am trying to import a module that's in this repo into a notebook also within the repo. The structure is as such:
Repo_Name
Checks.py
Test.ipynb
The path to this repo is in my sys.path(), yet I still get ModuleNotFoundError: No module named 'Checks'. When I try to do import Checks. This link explains that you should be able to import any modules that are in the PATH. Does anyone know why it might still not be working?
I have tried doing the same and got a similar error even after following the procedure as given in the link provided in the question.
I have the following python files in my GIT repo (3 files with .py extension).
Now when I add the path /Workspace/Repos/<username>/repro0812 to sys.path and try to import the sample module from this repo, it throws the same error.
This is because, for some reason, this file is not being rendered as a python file. When I open the repo, you can actually see the difference.
There was no problem while I import the other 2 python modules check and sample2. The following is an image for refernce.
Check and make sure that the file is being considered as a .py file after adding your repo.
I am trying to learn the linearmodels package for python.
I want to do this by practicing with the data sets, as can be seen here.
Example code:
import numpy as np
from linearmodels.iv import IV2SLS
from linearmodels.datasets import mroz
data = mroz.load()
But my code breaks when i run data = mroz.load()
error message:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\...\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\linearmodels\\datasets\\mroz\\mroz.csv.bz2'
I have pip version: 19.1.1
Conda can't find the package at all
and i have the latest version of linearmodels package: 4.13
The folder specified in the error message i can find, i.e. datasets\mroz but not the csv.bz2 file.
The same holds for every other data set i try to open.
Why am i not able to open the datasets?
let me know if you need additional information.
This is a bug in the package. If you download and unpack the source distribution you would find it lacks all *.csv.bz2.
I see two problems in the package. First, MANIFEST.in lists *.csv.bz. It must be *.csv.bz2 or *.csv.bz*.
Second, they tried to add the datasets in setup.py but also failed, not sure why. Perhaps the files must be declared as belonged to different subpackages, not to the main package.
Please report the bugs to the issue tracker.
I'm trying to use the Freesound API in a Google Colaboratory notebook (running Python 3) to generate a database of sounds for which to do machine learning with. However I have been unable to use the definitions in a module I imported.
I've looked at other similar questions but they did not seem to address my issue (most were cases of trying to import a module in the standard python library and instead importing a .py file of the same name) and I apologize if this particular issue has been covered somewhere else.
The boilerplate code is as follows:
#clone relevant Git repo
!git clone https://github.com/MoltenMuffins/freesound-python
!ls
#Import packages
import os
import sys
import requests
#Open module file and import module
open('freesound.py','wb')
import freesound
There is some code after that but it is not relevant to the issue. Running this last code block is what gives me the Attribute Error despite FreesoundClient being defined in the freesound.py file cloned from the repo:
freesound_client = freesound.FreesoundClient()
I would greatly appreciate an explanation regarding this issue!
Here's a link to the colabs notebook if you'd like to take a look
I would follow the repo's instructions of using their setup.py to do the installation:
After cloning the git repo, you want to change your working directory to the freesound-python directory and run setup.py
import os
os.chdir('/content/freesound-python')
!python setup.py install
# now import the module
import freesound
I am trying to use the nets from the official mnist directory of tensorflows model repository. On my windows system I receive this error:
C:\Users\ry\Desktop\NNTesting\models\official\mnist>mnist_test.py
Traceback (most recent call last):
File "C:\Users\ry\Desktop\NNTesting\models\official\mnist\mnist_test.py",line 24, in <module>
from official.mnist import mnist
ModuleNotFoundError: No module named 'official'
I have followed their official directions and set my python path using
set PYTHONPATH="PYTHONPATH:"%cd%"
and can confirm that
PYTHONPATH="$PYTHONPATH:C:\Users\ry\Desktop\NNTesting\models"
and I have also installed the dependencies successfully. Does anyone have experience using these models on a windows system and can help me with this pathing issue? I'm not sure what I have done incorrectly here.
Thanks
pip install tf-models-official
For Google Colab I needed to add the the model dir also to the Systems path:
!git clone https://github.com/tensorflow/models.git
import os
os.environ['PYTHONPATH'] += ":/content/models"
import sys
sys.path.append("/content/models")
if anyone has this problem make sure that the python path variable doesn't have quotations in it. For some reason, the readme has quotations around it.
Here is the correct way to set it
PYTHONPATH=path\to\models
I had exactly the same question as you did, and the following solution solved this problem.
There is an error in the tensorflow/models/official README.md
https://github.com/tensorflow/models/tree/master/official
Wrong
export PYTHONPATH="$PYTHONPATH:/path/to/models"
Correct
export PYTHONPATH=$PYTHONPATH:/path/to/models
The Official Models are made available as a Python module. To run the models and associated scripts, add the top-level /models folder to the Python path with the command: export PYTHONPATH="$PYTHONPATH:/path/to/models"
FROM README
I had the same problem. Did you use windows 10? Make sure you run the command prompt as "administrator". I used it in VS code at first, no warning, and didn't work. But it worked when I run a separate prompt window as "administrator".
set PYTHONPATH=path\to\models
then run the model.
I was setting up to run the NMT model and ran into the same problem.
It took me bit to figure out exactly which folder should be added to PYTHONPATH.
I tried several folders inside my example's directory with no luck.
I finally understood what that import was trying to tell me...
"from official.transformer.utils import tokenizer"
means
"add the parent of directory 'official' to PYTHONPATH".
For me, this was just the top-level 'models-master' directory that I obtained from GitHub. Once I added /path/to/models-master, I was past this obstacle.
Go to models folder and do
export PYTHONPATH=$PYTHONPATH:$PWD
add the model directory to PYTHONPATH.
import os
os.environ['PYTHONPATH'] += ':/content/models/research/:/content/models/research/slim/'
jupyter. Clone from official git and manually appended the path to sys.
!git clone https://github.com/tensorflow/models.git
import sys
sys.path.append("C:/Windows/System32/models")
sys.path
I'm trying to find the function or class definition of gen_dataset_ops in tensorflow, which has its sourcecode here. I find many places where it is imported like so:
from tensorflow.python.ops import gen_dataset_ops
But I can't find where it is defined, I'd expect to find something like:
def gen_dataset_ops(...):
#Do something clever
return
I don't quite understand the anatomy of python modules in general, so I'm probably missing some basics here,.. any hint is welcome!
tensorflow.python.ops.gen_dataset_ops is generated code. (That's why they put gen in front of the name.) You can't find it in the source repository because it's not in the source repository; it only comes into existence during the Tensorflow build process.
If you have Tensorflow installed, you should be able to find gen_dataset_ops.py under tensorflow/python/ops/gen_dataset_ops.py in your Tensorflow installation.
I would navigate to your python directory (this example is for a virtualenv on ubuntu):
~/pyEnvs/env1/lib/python2.7/site-packages/tensorflow/python/ops.py and open that file. In that file, use Ctrl+F and find the function you are looking for.
My answer assumes you know where your python environment is installed and that you installed tensorflow using pip